Hi,
I have data in the following form:
index count
-7 32
1 9382
2 2192
7 190
11 201
I'd like to get quantiles from the data. I thought about something like
this:
index <- c(-7, 1, 2, 7, 11)
count <- c(32, 9382, 2192, 190, 201)
quantile(rep(index, count))
It answers correctly, but I feel it's wasteful especially when count
is generally large. So, my question is, is there a way to get
quantiles directly from this table (without coding at a low level)?
Thanks,
Seung
You could use: require(quantreg) rq(index ~ 1, weights=count, tau=0:5/5) url: www.econ.uiuc.edu/~roger Roger Koenker email rkoenker at uiuc.edu Department of Economics vox: 217-333-4558 University of Illinois fax: 217-244-6678 Champaign, IL 61820 On Aug 28, 2007, at 9:22 AM, Seung Jun wrote:> Hi, > > I have data in the following form: > > index count > -7 32 > 1 9382 > 2 2192 > 7 190 > 11 201 > > I'd like to get quantiles from the data. I thought about something > like this: > > index <- c(-7, 1, 2, 7, 11) > count <- c(32, 9382, 2192, 190, 201) > quantile(rep(index, count)) > > It answers correctly, but I feel it's wasteful especially when count > is generally large. So, my question is, is there a way to get > quantiles directly from this table (without coding at a low level)? > > Thanks, > Seung > > ______________________________________________ > R-help at stat.math.ethz.ch 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.
See the wtd.quantile function in the Hmisc package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Seung Jun > Sent: Tuesday, August 28, 2007 8:23 AM > To: r-help at stat.math.ethz.ch > Subject: [R] quntile(table)? > > Hi, > > I have data in the following form: > > index count > -7 32 > 1 9382 > 2 2192 > 7 190 > 11 201 > > I'd like to get quantiles from the data. I thought about > something like this: > > index <- c(-7, 1, 2, 7, 11) > count <- c(32, 9382, 2192, 190, 201) > quantile(rep(index, count)) > > It answers correctly, but I feel it's wasteful especially > when count is generally large. So, my question is, is there > a way to get quantiles directly from this table (without > coding at a low level)? > > Thanks, > Seung > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >