On 23-Sep-10 16:52:09, Duncan Murdoch wrote:
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] 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
Or, perhaps more transparently (and more explicitly modifiable):