post
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-request at r-project.org> wrote:
Welcome to the R-help at r-project.org mailing list! To post to this list, send your email to: r-help at 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.dalgaard at biostat.ku.dk) FAX: (+45) 35327907