I think the question is more, "Why does it work in R?"
if(fallen[i-1] == 1) { .... } else { .... }
is what you are really trying to say.
But it looks to me like you can tell how many ones there
should be with:
log(runif(1)) / .94
Patrick Burns
patrick@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
Huso, Manuela wrote:
Dear S-news,
I want to create a vector of 0's and 1's whose elements are
conditional on the previous element. I start with a vector with 10
elements, the first of which is a 1. After that I want the following
elements to be 1 with probability 0.94. If any element becomes a 0,
then all succeeding elements should be 0. I wrote the following which
gave me fits trying to figure out why it doesn't work. I don't get
any error messages, it just doesn't change my 'fallen' vector.
fallen<-c(1,rep(0,9))
for (i in 2:10)
ifelse(fallen[i-1]==1,fallen[i]<-runif(1)<0.94,fallen[i]<-0)
Then I tried it in R. It worked perfectly. Can anyone tell me why it
doesn't work in S+, please?
Many thanks,
Manuela
*>::<>::<>::<>::<>::<>::<>::<>::<>::<>::<*
*Manuela Huso*
*Consulting Statistician*
*Department of Forest Science*
*201H Richardson Hall*
*Oregon State University*
*Corvallis, OR 97331*
*ph: 541.737.6232*
*fx: 541.737.1393*
|