[R] Aggregation using list with Hmisc summarize function

Gabor Grothendieck ggrothendieck at gmail.com
Thu Dec 28 17:37:32 CET 2006


Note that you don't really need list or llist in this case:

summarize(x, by = mydata[2:3], FUN = mean, na.rm = TRUE)

Also you could use aggregate:

aggregate(mydata[1], mydata[2:3], mean, na.rm = TRUE)


On 12/28/06, Muenchen, Robert A (Bob) <muenchen at utk.edu> wrote:
> Hi All,
>
>
>
> I'm using the Hmisc summarize function and used list instead of llist to
> provide the by variables. It generated an error message. Is this a bug,
> or do I misunderstand how Hmisc works with lists? The program below
> demonstrates the error message.
>
>
>
> Thanks,
>
> Bob
>
>
>
> x<-1:8
>
> group <- c(1,1,1,1,2,2,2,2)
>
> gender<- c(1,2,1,2,1,2,1,2)
>
>
>
> mydata<-data.frame(x,group,gender)
>
> attach(mydata)
>
>
>
> # Creating a list using Hmisc llist works:
>
> summarize(x, by=llist(group,gender), FUN=mean, na.rm=TRUE)
>
>
>
> # Creating a list using built-in list function does not:
>
> summarize(x, by= list(group,gender), FUN=mean, na.rm=TRUE)
>
>
>
> =========================================================
> Bob Muenchen (pronounced Min'-chen), Manager
> Statistical Consulting Center
> U of TN Office of Information Technology
> 200 Stokely Management Center, Knoxville, TN 37996-0520
> Voice: (865) 974-5230
> FAX: (865) 974-4810
> Email: muenchen at utk.edu
> Web: http://oit.utk.edu/scc <http://oit.utk.edu/scc> ,
> News: http://listserv.utk.edu/archives/statnews.html
> <http://listserv.utk.edu/archives/statnews.html>
> =========================================================
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list