All - I have an example data frame x l.c.1 43.38812035 085 47.55710661 085 47.55710661 085 51.99211429 085 51.99211429 095 54.78449958 095 54.78449958 095 56.70201864 095 56.70201864 105 59.66361903 105 61.69573564 105 61.69573564 105 63.77469479 115 64.83191994 115 64.83191994 115 66.98222118 115 66.98222118 125 66.98222118 125 66.98222118 125 66.98222118 125 and I'd like to get the 3rd quantile by l.c.1 so I use tapply(x, l.c.1, quantile) and my output includes all quantiles (i.e., 0, 25%, 50%, 75%, 100%) but I'm only interested in the 75% quantile. Is there an additional statement or function I can use to get just the quantile that I want? Thanks for your help - SR Steven H. Ranney
Hi Steven, See the prob argument under ?quantile. The following should be what you want: tapply(x, l.c.1, quantile, prob = 0.75) HTH, Jorge * * On Thu, Mar 24, 2011 at 7:18 PM, Steven Ranney <> wrote:> All - > > I have an example data frame > > x l.c.1 > 43.38812035 085 > 47.55710661 085 > 47.55710661 085 > 51.99211429 085 > 51.99211429 095 > 54.78449958 095 > 54.78449958 095 > 56.70201864 095 > 56.70201864 105 > 59.66361903 105 > 61.69573564 105 > 61.69573564 105 > 63.77469479 115 > 64.83191994 115 > 64.83191994 115 > 66.98222118 115 > 66.98222118 125 > 66.98222118 125 > 66.98222118 125 > 66.98222118 125 > > and I'd like to get the 3rd quantile by l.c.1 so I use > > tapply(x, l.c.1, quantile) > > and my output includes all quantiles (i.e., 0, 25%, 50%, 75%, 100%) > but I'm only interested in the 75% quantile. Is there an additional > statement or function I can use to get just the quantile that I want? > > Thanks for your help - > > SR > Steven H. Ranney > > ______________________________________________ > 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]]
Tena koe Steven The ... argument of the apply series of functions allows one to pass arguments to the called function. So: tapply(x, l.c.1, quantile, probs=0.75) should work (although I haven't tested it). HTH ..... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Steven Ranney > Sent: Friday, 25 March 2011 12:18 p.m. > To: r-help at r-project.org > Subject: [R] tapply with specific quantile value > > All - > > I have an example data frame > > x l.c.1 > 43.38812035 085 > 47.55710661 085 > 47.55710661 085 > 51.99211429 085 > 51.99211429 095 > 54.78449958 095 > 54.78449958 095 > 56.70201864 095 > 56.70201864 105 > 59.66361903 105 > 61.69573564 105 > 61.69573564 105 > 63.77469479 115 > 64.83191994 115 > 64.83191994 115 > 66.98222118 115 > 66.98222118 125 > 66.98222118 125 > 66.98222118 125 > 66.98222118 125 > > and I'd like to get the 3rd quantile by l.c.1 so I use > > tapply(x, l.c.1, quantile) > > and my output includes all quantiles (i.e., 0, 25%, 50%, 75%, 100%) > but I'm only interested in the 75% quantile. Is there an additional > statement or function I can use to get just the quantile that I want? > > Thanks for your help - > > SR > Steven H. Ranney > > ______________________________________________ > 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.The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited.
Just have a look at ?quantile and the probs argument. tapply(x, l.c.1, quantile,probs=0.75) Anyway, quantiles and quartiles are not the same. I guess you meant the 3rd quartile.> All - > > I have an example data frame > > x l.c.1 > 43.38812035 085 > 47.55710661 085 > 47.55710661 085 > 51.99211429 085 > 51.99211429 095 > 54.78449958 095 > 54.78449958 095 > 56.70201864 095 > 56.70201864 105 > 59.66361903 105 > 61.69573564 105 > 61.69573564 105 > 63.77469479 115 > 64.83191994 115 > 64.83191994 115 > 66.98222118 115 > 66.98222118 125 > 66.98222118 125 > 66.98222118 125 > 66.98222118 125 > > and I'd like to get the 3rd quantile by l.c.1 so I use > > tapply(x, l.c.1, quantile) > > and my output includes all quantiles (i.e., 0, 25%, 50%, 75%, 100%) > but I'm only interested in the 75% quantile. Is there an additional > statement or function I can use to get just the quantile that I want? > > Thanks for your help - > > SR > Steven H. Ranney > > ______________________________________________ > 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. >