[R] summing columns of data frame by group

2007-08-21 Thread Daniel O'Shea
I have a data frame and one separate vector that is a grouping variable for the data frame. I would like to take all rows of the data frame belonging to each group and then sum the columns with out using a for statement. Something like: take all rows of group 1 then apply(group1.data,1,sum),

Re: [R] summing columns of data frame by group

2007-08-21 Thread John Kane
?by perhaps --- Daniel O'Shea [EMAIL PROTECTED] wrote: I have a data frame and one separate vector that is a grouping variable for the data frame. I would like to take all rows of the data frame belonging to each group and then sum the columns with out using a for statement. Something

Re: [R] summing columns of data frame by group

2007-08-21 Thread bogdan romocea
Here's one way, lapply(split(DF, your.vector), function(x) {apply(x, 2, sum)}) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Daniel O'Shea Sent: Tuesday, August 21, 2007 3:53 PM To: r-help@stat.math.ethz.ch Subject: [R] summing columns of data