I am just starting to use dplyr and converting part of my plyr code. I like the new syntax, but it's hard for me to get mutate () to apply a function in a column by group, for example:
library(Hmisc)
library(plyr)
library(dplyr)
t1 <- ddply(mtcars, .(cyl), transform, qrt=cut2(wt, g=4))
levels(t1$qrt)
t2 <- mtcars %>% group_by(cyl) %>% mutate(qrt=cut2(wt, g=4))
levels(t2$qrt)
At first I thought that the second example uses the entire column wtinstead of groups cyl, but in reality it seems to use only quartiles for the first group and assigns them to all groups, even if it wtis out of range.
Am I missing the syntax around a link wtinside a function in a mutation? Can I get the ddply version to work for features like sum(), so is something about cut2()causing a problem?
, , dplyr ddply, .
!