[R] Summary of data.frame according to colnames and grouping factor
soeren.vogel at eawag.ch
soeren.vogel at eawag.ch
Sun Mar 8 18:14:23 CET 2009
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"), 10)
### end:example
How do I get the count of "1's" (or any other function) applied over
each var according to the grouping? That is:
Desired output table:
A B C
r count count count
s ... ... ...
or likewise transposed. I'd like to use the table for textual display
and/or barplot creation.
Thx, Sören
--
Sören Vogel, PhD-Student, Eawag, Dept. SIAM
http://www.eawag.ch, http://sozmod.eawag.ch
More information about the R-help
mailing list