[R] prettyR 25% quartile, 75% quartile

Jim Lemon jim at bitwrit.com.au
Fri Apr 4 12:15:23 CEST 2008


stephen sefick wrote:
> I am using the describe function in prettyR.  I would like to add the
> 25% 75% quartiles to the summary table
> 
> how do I do this
> 
> I have tried
> 
> describe(x.f, num.desc=c("mean", "median", "sd", "min", "max",
> "skewness", "quantile(x.f, na.rm=T, probs=seq(0.25, 0.75))",
> "valid.n"))
> 
Hi Stephen,
If you want to run your own summary function within "describe", you have 
to write a "wrapper" function that can be called by its name (unless I 
radically rewrite "describe.numeric" so that a list of arguments can be 
included). Additionally, the function should return a single value 
(otherwise the "pretty" columnar display is messed up). So:

q25<-function(x,na.rm) {
  return(quantile(x,probs=0.25,na.rm=na.rm))
}
q75<-function(x,na.rm) {
  return(quantile(x,probs=0.75,na.rm=na.rm))
}
describe(x.f, num.desc=c("mean", "median", "sd", "min", "max",
"skewness","q25","q75","valid.n"))

You have anticipated the help file of the latest version (1.3) that 
shows how to write a little wrapper for describe.numeric. Very good.

Jim



More information about the R-help mailing list