Skip to content

column selection for aggregate()

11 messages · b k, Ivan Calandra, Gabor Grothendieck +1 more

#
Try summaryBy in the doBy package. e.g. using the built-in CO2
summarize each numeric variable by each factor except for the factors
Plant and Type:

library(doBy)
summaryBy(. ~ ., data = subset(CO2, select = - c(Plant, Type)))


On Mon, Jan 18, 2010 at 9:53 AM, Ivan Calandra
<ivan.calandra at uni-hamburg.de> wrote:
#
It looks ok except you have both specified the wanted factors and
removed the undesired factors from the data frame.  You only need to
do one of these as in the example I gave, not both, so the solution
could be simpler.

On Mon, Jan 18, 2010 at 11:19 AM, Ivan Calandra
<ivan.calandra at uni-hamburg.de> wrote:
#
Hi

If I really wanted aggregate all numerics by all non numerics this is how 
I would do it

my.numerics <- which(sapply(zeta, is.numeric))
my.factor <- which(sapply(zeta, is.factor))
aggregate(zeta[, my.numerics], zeta[, my.factor], mean)

Regards
Petr



r-help-bounces at r-project.org napsal dne 18.01.2010 16:33:17:
http://www.R-project.org/posting-guide.html