From istazahn at gmail.com  Fri Mar 23 23:57:05 2018
From: istazahn at gmail.com (Ista Zahn)
Date: Fri, 23 Mar 2018 18:57:05 -0400
Subject: [Rd] aggregate() naming -- bug or feature
In-Reply-To: <031f02b9-a6eb-cc2b-7c7b-286dc5b7bf68@sapo.pt>
References: <9187C1DA-5061-4ABD-9D7C-D536BB134BD6@calvin.edu>
 <031f02b9-a6eb-cc2b-7c7b-286dc5b7bf68@sapo.pt>
Message-ID: <CA+vqiLHze0icMj=M8RL7TtEXWdP7QUkMYNpimCn=6b_Dfv=_yA@mail.gmail.com>

On Fri, Mar 23, 2018 at 6:43 PM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
> Hello,
>
> Not exactly an answer but here it goes.
> If you use the formula interface the names will be retained.

Also if you pass named arguments:

aggregate(iris["Sepal.Length"], by = iris["Species"], FUN = foo)
#      Species Sepal.Length
# 1     setosa        5.006
# 2 versicolor        5.936
# 3  virginica        6.588

If fact, this
> is even better than those names assigned by bar.
>
>
> aggregate(Sepal.Length ~ Species, data = iris, FUN = foo)
> #     Species Sepal.Length
> #1     setosa        5.006
> #2 versicolor        5.936
> #3  virginica        6.588
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> On 3/23/2018 1:29 PM, Randall Pruim wrote:
>>
>> In the examples below, the first loses the name attached by foo(), the
>> second retains names attached by bar().  Is this an intentional difference?
>> I?d prefer that the names be retained in both cases.
>>
>> foo <- function(x) { c(mean = base::mean(x)) }
>> bar <- function(x) { c(mean = base::mean(x), sd = stats::sd(x))}
>> aggregate(iris$Sepal.Length, by = list(iris$Species), FUN = foo)
>> #>      Group.1     x
>> #> 1     setosa 5.006
>> #> 2 versicolor 5.936
>> #> 3  virginica 6.588
>> aggregate(iris$Sepal.Length, by = list(iris$Species), FUN = bar)
>> #>      Group.1    x.mean      x.sd
>> #> 1     setosa 5.0060000 0.3524897
>> #> 2 versicolor 5.9360000 0.5161711
>> #> 3  virginica 6.5880000 0.6358796
>>
>> ?rjp
>>
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] aggregate() naming -- bug or feature
Ista Zahn