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,
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
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
3 matches
Mail list logo