how can I do this calculation:
library(ddply)
quantile(baseball$ab)
0% 25% 50% 75% 100%
0 25 131 435 705
by groups, say by "team"? I want a data.frame with rownames "team" and column names "0% 25% 50% 75% 100%", i.e. one quantile
call per group.
doing
ddply(baseball,"team",quantile(ab))
is not the correct solution. my problem is that the OUTPUT of each grouped operation is a vector of length 5 here.
in other words, what's a neat solution to this (nevermind the header):
m=data.frame()
for (i in unique(baseball$team)){m=rbind(m,quantile(baseball[baseball$team==i, ]$ab))}
head(m,3)
X120 X120.1 X120.2 X120.3 X120.4
1 120 120.0 120.0 120.00 120
2 162 162.0 162.0 162.00 162
3 89 89.0 89.0 89.00 89