[R] Calculating percentiles from Grouped Data (gapply)

Patrick Hausmann patrick.hausmann at uni-bremen.de
Wed Mar 3 11:53:30 CET 2004


Dear R-list,

I try to calculate the 10- and 90-Percentile from grouped data.
Using 'lappy' it works fine but I have no success with 'gapply':
 
df <- data.frame(test = runif(100))
df <- df[order(df[,1]),]
z <- rep(1:10, each = 10)
lapply(split(df, z), function(x) quantile(x, probs=c(10,90)/100))

library(nlme)
gapply(as.data.frame(df), which=1, 
          function(x) quantile(x, probs=c(10,90)/100), group=z)
#  Error in sort(x, partial = unique(c(lo, hi))) : 
#    `x' must be atomic

Thanks for any help
Patrick




More information about the R-help mailing list