# Collapsing data into the level of certain variables and taking averages

**URL:** https://discourse.julialang.org/t/collapsing-data-into-the-level-of-certain-variables-and-taking-averages/56600
**Category:** New to Julia
**Tags:** dataframes
**Created:** [March 6, 2021, 2:24am UTC](https://discourse.julialang.org/t/collapsing-data-into-the-level-of-certain-variables-and-taking-averages/56600 "2021-03-06T02:24:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![samerb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samerb/32/9242_2.png) [@samerb](https://discourse.julialang.org/u/samerb)
#### Post date: [March 6, 2021, 2:24am UTC](https://discourse.julialang.org/t/collapsing-data-into-the-level-of-certain-variables-and-taking-averages/56600/1 "2021-03-06T02:24:26Z")

</div>

Let’s say I have a data frame with columns A1,A2,A3,…,An, where A1,A2,A3 are categorical variables and the rest are floats. I want to create a new data frame (or equivalent) with the following features:

1. there is one row for each possible combination of variables A1, A2, A3
2. The columns are A4,…,An
3. The value in a given row-column entry is the average of that column of all the rows with that particular combination of values of A1,A2,A3.

I believe `groupby([:A1, :A2, :A3])` will be used somehow but not sure how.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [March 6, 2021, 5:28am UTC](https://discourse.julialang.org/t/collapsing-data-into-the-level-of-certain-variables-and-taking-averages/56600/2 "2021-03-06T05:28:13Z")

</div>

```julia
combine(groupby(df, [:A1, :A2, :A3]), names(df, Between(:A4, :A10)) .=> mean)

```
