Maas James Dr (MED)
2011-Feb-17 10:08 UTC
[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
ONKELINX, Thierry
2011-Feb-17 10:18 UTC
[R] removing lower and upper quantiles from an arry
You need two logical test and then combine them with & (AND) or | (OR) i[quantile(i,.25) >= i & i <= quantile(i,.75)] Best regards, Thierry ---------------------------------------------------------------------------- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics & Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx at inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey> -----Oorspronkelijk bericht----- > Van: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] Namens Maas James Dr (MED) > Verzonden: donderdag 17 februari 2011 11:09 > Aan: r-help at r-project.org > Onderwerp: [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. >
Dimitris Rizopoulos
2011-Feb-17 10:20 UTC
[R] removing lower and upper quantiles from an arry
have a look at the help page for ?'&', try also this: i <- 1:20 qs <- quantile(i, c(.25, 0.75)) i[i > qs[1] & i < qs[2]] I hope it helps. Best, Dimitris On 2/17/2011 11:08 AM, Maas James Dr (MED) wrote:> 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. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/
andrija djurovic
2011-Feb-17 10:25 UTC
[R] removing lower and upper quantiles from an arry
Try this: i[quantile(i,.25)< i & i < quantile(i,.75)] Andrija On Thu, Feb 17, 2011 at 11:08 AM, Maas James Dr (MED) <J.Maas@uea.ac.uk>wrote:> 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@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. >[[alternative HTML version deleted]]
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20110217/e1f300a5/attachment.pl>
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20110217/d0271439/attachment.pl>
Here's one more way: i[ findInterval(i, quantile(i, c(.25, .75))) == 1 ] Peter Ehlers On 2011-02-17 02:08, Maas James Dr (MED) wrote:> 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.
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.