Patrick Hausmann wrote:
> 
> 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


For use with quantile(), you have to make x in your anonymous function a
vector as in:

  gapply(as.data.frame(df), which=1,
      function(x) quantile(x[[1]], probs=c(10,90)/100), group=z)


Uwe Ligges

> Thanks for any help
> Patrick
> 
> ______________________________________________
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to