[R] removing lower and upper quantiles from an arry
Greg Snow
Greg.Snow at imail.org
Thu Feb 17 18:53:07 CET 2011
In addition to the other answers that you received you can also do:
library(TeachingDemos)
i[ quantile(i,.25) %<% i %<% quantile(i,.75) ]
This may or may not be more readable than the others. Also note that precomputing both quantiles in one step may be faster than calling quantile twice.
You could also do a partial sort of your data and just pull out the middle section (though you would probably lose the ordering in the data).
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Maas James Dr (MED)
> Sent: Thursday, February 17, 2011 3:09 AM
> To: r-help at r-project.org
> Subject: [R] removing lower and upper quantiles from an arry
>
> I'm trying to work out the simplest way to remove the upper and lower
> quantiles, in this case upper and lower 25% from an array. I can do it
> in two steps but when I try it in one, it fails. Is there something
> simple missing from my syntax or are there other simple elegant way to
> accomplish this?
>
> Thanks
>
> J
>
> > i <-1:20
> > i2 <- i[i<quantile(i,.75)]
> > i3 <- i[i>quantile(i,.25)]
> > i4 <- i[quantile(i,.25)< i > quantile(i,.75)]
> Error: unexpected '>' in "i4 <- i[quantile(i,.25)< i >"
>
> ===============================
> Dr. Jim Maas
> University of East Anglia
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list