I think the following does what you want: data.rowsum <- apply(data, 1, function(x) tapply(x, c.factor, sum)) BTW, I don't think you need to have c.factor as a factor. HTH, Andy -----Original Message----- From: Jeremy Z Butler [mailto:jeremybutler at paradise.net.nz] Sent: Wednesday, December 11, 2002 10:06 PM To: r-help at stat.math.ethz.ch Subject: [R] splitting columns into groups Hi, I'm trying to split 96 columns into 8 groups and then obtain row totals for each of those groups. But: c.factor <- as.factor(c(rep(1:8,c(18,12,12,12,6,12,12,12))) data.groups <- split(data,c.factor) splits my rows into those groups. Is there anyway I can tell R to apply the split function to columns or am I doing something wrong when creating "c.factor" Cheers, Jeremy ______________________________________________ R-help at stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help ------------------------------------------------------------------------------
splitting columns into groups
1 message · Liaw, Andy