[R] Aggregation using list with Hmisc summarize function

Frank E Harrell Jr f.harrell at vanderbilt.edu
Thu Dec 28 17:28:00 CET 2006


Muenchen, Robert A (Bob) 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)

Use llist so summarize will know how to label the output.

Also your attach( ) is not functional as your variables are already in 
the search path.  Whenever you do need to attach, consider the use of 
with( ) instead.

Frank

> 
>  
> 
> =========================================================
> Bob Muenchen (pronounced Min'-chen), Manager 
> Statistical Consulting Center
> U of TN Office of Information Technology


-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list