You can use the quantile function from the Hmisc package, which allows weights.
Hmisc::wtd.quantile(as.numeric(names(table_s)),weights = table_s)
Question
s is a large array, just save table(s) in database
> table_s
s
1 2 3 4 5
3000000 1 1 999999999999999999 34
how to calc quantile(s) with table_s in R ?
thanks
Solution
You can use the quantile function from the Hmisc package, which allows weights.
Hmisc::wtd.quantile(as.numeric(names(table_s)),weights = table_s)
OTHER TIPS
The simplest (but computationally expensive) way I can think of is to re-expand your table into a vector of observations and use the quantile
function:
s <- c(3000000,1,1,999999999999999999,34)
names(s) <- 1:5
quantile(rep.int(as.integer(names(s)),times=s))
# 0% 25% 50% 75% 100%
# 1 4 4 4 5
If you are looking for something faster, then you might need to write your own function.
EDIT: As Matthew Lundberg states in the comments, the code above doesn't work. It will run only if sum(s)
is less than the maximum possible length of a vector, which is currently 2^31-1 < 10^10.