[R] Compute quantiles with values and correspondent frequencies

Frank E Harrell Jr f.harrell at vanderbilt.edu
Fri Mar 3 16:09:09 CET 2006


Roger Bivand wrote:
> On Fri, 3 Mar 2006, Paolo Radaelli wrote:
> 
> 
>>Dear List, quantile(x) function allows to obtain specified quantiles of
>>a vector of observations x.
>>
>>Is there an analogous function to compute quantiles in the case one have
>>the vector of the observations x and the correspondent vector f of
>>relative frequencies ?
> 
> 
> Just use rep():
> 
> x <- rpois(100, 4) # data
> quantile(x)
> tx <- table(x) # frequencies (need to be integer counts)
> tx
> v <- as.numeric(names(tx)) # values
> quantile(rep(v, as.integer(tx)))
> 
> You have v and tx, so this should work.
> 
> 
>>Thank you
>>
>>Paolo Radaelli
>>
>>
>>
>>	[[alternative HTML version deleted]]
>>
>>______________________________________________
>>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
>>
> 
> 

Look at wtd.quantile in the Hmisc package.

Frank

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University




More information about the R-help mailing list