tags:

views:

87

answers:

1

When using plyr, I often want to 1) perform an operation on only a subset of the variables and 2) name the output of the operation. For example:

d = data.frame(sex=c("m","f","m","m","f","f"), age=c(30,20,15,50,10,40), weight=c(130,120,115,150,90,180))
ddply(d, .(sex), function(df) data.frame(age_mu = mean(df$age)))

But this seems kinda clunky, and it seems like I should be able to write something like:

ddply(d, .(sex), age_mu = mean(age))

From what I've read, it looks like there is (or used to be?) a summarise function included in plyr, that would allow me to write:

ddply(d, .(sex), transform, age_mu = mean(age))

However, when I try to use the summarise function, R tells me it doesn't exist. Has it been renamed or moved into another package? I'm using plyr version 0.1.5 (which I believe is the latest -- I tried updating) on a Mac.

+1  A: 

Yes, it still exists there. I'm using plyr version 1.1 so your version seems to be very old.

atricapilla