What would be the best tool/package to use to calculate proportions by subgroups? I thought I could try something like this:
data(mtcars)
library(plyr)
ddply(mtcars, .(cyl), transform, Pct = gear/length(gear))
But the output is not what I want, as I would want something with a number of rows equal to cyl
. Even if change it to summarise
i still get the same problem.
I am open to other packages, but I thought plyr
would be best as I would eventually like to build a function around this. Any ideas?
I'd appreciate any help just solving a basic problem like this.