[R] "reverse" quantile function
David Winsemius
dwinsemius at comcast.net
Fri Jun 16 00:46:36 CEST 2017
> On Jun 15, 2017, at 12:37 PM, Andras Farkas via R-help <r-help at r-project.org> wrote:
>
> Dear All,
>
> we have:
>
> t<-seq(0,24,1)
> a<-10*exp(-0.05*t)
> b<-10*exp(-0.07*t)
> c<-10*exp(-0.1*t)
> d<-10*exp(-0.03*t)
> z<-data.frame(a,b,c,d)
>
> res<-t(apply(z, 1, quantile, probs=c(0.3)))
>
>
>
> my goal is to do a 'reverse" of the function here that produces "res" on a data frame, ie: to get the answer 0.3 back for the percentile location when I have "res" available to me... For a single vector this would be done using ecdf something like this:
>
> x <- rnorm(100)
> #then I know this value:
> quantile(x,0.33)
> #so do this step
> ecdf(x)(quantile(x,0.33))
> #to get 0.33 back...
>
> any suggestions on how I could to that for a data frame?
Can't you just used ecdf and quantile ecdf?
# See ?ecdf page for both functions
> lapply( lapply(z, ecdf), quantile, 0.33)
$a
33%
4.475758
$b
33%
3.245151
$c
33%
2.003595
$d
33%
6.173204
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list