Re: [R] Summary of data.frame according to colnames and grouping factor

2009-03-08 Thread David Winsemius
If you prefer to do it with base functions, you could start by thinking about one column at a time, for which the tapply function is a logical choice: > tapply(d[,"A"], e, sum) r s 3 6 Then wrap that in an apply call that handles each column sequentially: > apply(d, 2, function (x) tapply(x,

Re: [R] Summary of data.frame according to colnames and grouping factor

2009-03-08 Thread baptiste auguie
Hi, You could use the reshape package: d$e <- e recast(d, variable~e, fun=sum) The doBy package is another option. baptiste On 8 Mar 2009, at 17:14, soeren.vo...@eawag.ch wrote: A dataframe holds 3 vars, each checked true or false (1, 0). Another var holds the grouping, r and s: ### s

[R] Summary of data.frame according to colnames and grouping factor

2009-03-08 Thread soeren . vogel
A dataframe holds 3 vars, each checked true or false (1, 0). Another var holds the grouping, r and s: ### start:example set.seed(20) d <- data.frame(sample(c(0, 1), 20, replace=T), sample(c(0, 1), 20, replace=T), sample(c(0, 1), 20, replace=T)) names(d) <- c("A", "B", "C") e <- rep(c("r", "s