I'm trying to replace all my plyr
calls with dplyr
. There are still a few snags and one of them is with the group_by
function. I imagine it acts the same way as the second ddply
argument and does a split, apply and combine based on the grouping variables I list. But that doesn't appear to be the case. Here is a rather trivial example.
Let's define a silly function
mm <- function(x) return(x[1:5, ])
Now we can split the species in the iris
dataset like so and apply this function to each piece.
ddply(iris, .(Species), mm)
This works as intended. However, when I try the same with dplyr
, it doesn't work as expected.
iris %>% group_by(Species) %>% mm
What am I doing wrong?