Create a quantile function given a discrete CDF in R that can handle
So, for example, I have a discrete function with CDF like this:
cdf <- c(0.00, 0.35, 0.71, 0.92, 1.00, 1.00, 1.00, 1.00)
I can create a quantile function with the following line.,.
result <- which(cdf == min(cdf[cdf > x]))
., where x is the cumulative probability. So, for example, qfunction (0.9) = 4 and qfunction (0.99) = 5.
This solution seems fine (albeit inelegant) until I handle vectors. So if x = c (0.9, 0.99) my function falls down. It looks like people would be doing a lot in R and yet I haven't found a solution. R is not my primary language.
Any help would be appreciated.
+3
source to share