On 23/09/2010 11:42 AM, wangguojie2006 wrote:
b<-runif(1000,0,1)
f<-density(b)

f is a list of things, including x values where the density is computed, and y values for the density there. So you could do it by linear interpolation using approx or approxfun. For example

> b <- runif(1000,0,1)
> flist <- density(b)
> f <- approxfun(flist$x, flist$y)
> f(0.2)
[1] 0.9717893
> f(-1)
[1] NA

If you don't like the NA for an out-of-range argument, then choose something different from the default for the "rule" argument to approxfun.

Duncan Murdoch

______________________________________________
R-help@r-project.org 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.

Reply via email to