Anastasia wrote:
> Dear all,
> 
> I have the following problem which I cannot solve:
> 
> data <- numeric (100)
> for (i in 1:100){
>   p <- runif(1,min=0,max=1)
>   data[i] <- rnorm(1,mean=2,sd=1)
> }

Er what is "p" doing in there. As far as I can see, you might as well do

data <- rnorm(200, 2, 1)

> ke <- density(data,bw="sj",n=61)

> How can I now find the value of this density function for example ke(0),
> ke(2) etc.
> Maybe this is an easy question but I cannot resolve it.

approxfun is your friend, e.g.:

> d <- density(rnorm(200,2,1))
> dd <- approxfun(d)
> dd(3)
[1] 0.2267764
> dd(5)
[1] 0.006181384
> dd(20) # from default rule=1 in approxfun
[1] NA

> 
> Thank you very much for the help.
> 
> 


And, BTW, please don't hijack old mails for new topics (and in
particular, don't show your password to the world):
> On Fri, Nov 27, 2009 at 3:34 PM, <r-help-requ...@r-project.org> wrote:
> 
>> Welcome to the R-help@r-project.org mailing list!
>>
>> To post to this list, send your email to:
>>
>>  r-help@r-project.org
-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalga...@biostat.ku.dk)              FAX: (+45) 35327907

______________________________________________
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.
  • [R] post Anastasia
    • Re: [R] post Peter Dalgaard

Reply via email to