s-news
[Top] [All Lists]

Simple conditional loop

To: <s-news@lists.biostat.wustl.edu>
Subject: Simple conditional loop
From: "Huso, Manuela" <manuela.huso@oregonstate.edu>
Date: Tue, 29 May 2007 11:52:00 -0700
In-reply-to: <8C96912ADB6C413-9DC-7C31@mblk-r19.sysops.aol.com>
References: <8C96912ADB6C413-9DC-7C31@mblk-r19.sysops.aol.com>
Thread-index: Acea+61IqbSO1yaMRPuSCgAyW1HHdwHJcolQ
Thread-topic: Simple conditional loop
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

 
<Prev in Thread] Current Thread [Next in Thread>