# Aggregate deprecated use combine

**URL:** <https://discourse.julialang.org/t/aggregate-deprecated-use-combine/42809>\
**Category:** Data\
**Tags:** dataframes\
**Created:** [July 9, 2020, 9:58pm UTC](https://discourse.julialang.org/t/aggregate-deprecated-use-combine/42809 "2020-07-09T21:58:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jguo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jguo/32/16283_2.png) [@jguo](https://discourse.julialang.org/u/jguo)\
**Post date:** [July 9, 2020, 9:58pm UTC](https://discourse.julialang.org/t/aggregate-deprecated-use-combine/42809/1 "2020-07-09T21:58:03Z")

</div>

dear Julia Community,

I am new to Julia. Here is my problem using aggregate function.

```julia
using DataFrames
df6 = DataFrame(Group = rand(["A", "B", "C"], 15), Variable1 = randn(15), Variable2 = rand(15));
aggregate(df6, :Group, [mean, std]);

```

I have the following warning.

> Warning: `aggregate(d, cols, fs, sort=false, skipmissing=false)` is deprecated. Instead use `combine(groupby(d, cols, sort=false, skipmissing=false), [names(d, Not(cols)) .=> f for f in fs]...)` if functions in `fs` have unique names.

Don’t quite understand what it means `[names(d, Not(cols)) .=> f for f in fs]`  
Could someone show me how to rewrite this line with `combine`?

Thanks,  
Jian

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [July 9, 2020, 10:11pm UTC](https://discourse.julialang.org/t/aggregate-deprecated-use-combine/42809/2 "2020-07-09T22:11:55Z")

</div>

Here is a way where you explicitly list out the columns on which you want statistics

```julia
combine(groupby(df6,:Group),[:Variable1,:Variable2] .=> [mean,std])

```

@pdeffebach will come through with a more elegant solution in a few posts I’m sure.

---

<div class="post-metadata">

**Author:** ![jguo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jguo/32/16283_2.png) [@jguo](https://discourse.julialang.org/u/jguo)\
**Post date:** [July 9, 2020, 10:25pm UTC](https://discourse.julialang.org/t/aggregate-deprecated-use-combine/42809/3 "2020-07-09T22:25:24Z")

</div>

@tbeason thanks for the hint.

It returns mean(Var1) and std(Var2) groupby(group).

However, I expect mean(Var1),std(Var1),mean(Var2),std(Var2), groupby(group)

How to realize it?

Have a great day! 🙂

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [July 9, 2020, 10:34pm UTC](https://discourse.julialang.org/t/aggregate-deprecated-use-combine/42809/4 "2020-07-09T22:34:42Z")

</div>

Whoops sorry I guess I didn’t pay enough attention!

Here is one way to do both

```julia
combine(groupby(df6,:Group),([:Variable1,:Variable2] .=> f for f in (mean,std))...)

```

which is kind of shorthand for

```julia
combine(groupby(df6,:Group),[:Variable1,:Variable2] .=> mean,[:Variable1,:Variable2] .=> std)

```

---

<div class="post-metadata">

**Author:** ![jguo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jguo/32/16283_2.png) [@jguo](https://discourse.julialang.org/u/jguo)\
**Post date:** [July 9, 2020, 10:45pm UTC](https://discourse.julialang.org/t/aggregate-deprecated-use-combine/42809/5 "2020-07-09T22:45:51Z")

</div>

@tbeason thanks a lot. It works as expected.

I knew where I got stuck. What do the trailing dots mean in this line?

> [@tbeason](#):
>
> `f for f in (mean,std))...`

---

<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:** [July 9, 2020, 11:03pm UTC](https://discourse.julialang.org/t/aggregate-deprecated-use-combine/42809/6 "2020-07-09T23:03:45Z")

</div>

The trailing dots are [`splatting`](https://docs.julialang.org/en/v1/manual/faq/#What-does-the-...-operator-do?-1). Say you have a function

```julia
fun(x, y, z)

```

but you only have your variables in a vector `t = [1, 2, 3]`. Then you can do

```julia
fun(t...)

```

I don’t think I have a better idea of how to do what you want than what is given in the warning message. It’s definitely wordier, but that’s the price we pay for reducing the surface of the API a bit.

---

<div class="post-metadata">

**Author:** ![jguo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jguo/32/16283_2.png) [@jguo](https://discourse.julialang.org/u/jguo)\
**Post date:** [July 9, 2020, 11:25pm UTC](https://discourse.julialang.org/t/aggregate-deprecated-use-combine/42809/7 "2020-07-09T23:25:28Z")

</div>

Thanks Peter! It looks like equivalent to `*` unpacking a list in Python.
