Re: [R] summing values by group

From: Mwalili, S. M. <samuel_mwalili_at_yahoo.com>
Date: Sat 26 Mar 2005 - 22:02:56 EST


Dear Larry,  

dat <- data.frame(CAT=sample(c("a","b","c","d"),100,rep=T), x=rnorm(100))  tapply(dat[,2],dat[,1, drop = FALSE], mean)  tapply(dat[,2],dat[,1, drop = FALSE], sum)  

I hope this helps,
Samuel.

Larry White <ljw1001@gmail.com> wrote:
At the risk of being wacked for asking what should be obvious....

I have a data frame with one categorical variable "CAT" and several numeric variables. I want to be able to get simple statistics on the numeric variables by level. For example, just as you can use table (CAT) to get the counts, I'd like to be able to get the means and sums by category.

If someone could point me in the right direction, I'd appreciate it. I've been through the SimpleR and Using R for Data Analysis... docs and I'm still clueless.

thanks for your help.



R-help@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                 

        [[alternative HTML version deleted]]



R-help@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 Received on Sat Mar 26 22:22:49 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:56 EST