| 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 >::<>::<>::<>::<>::<>::<>::<>::<>::<>::< |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: unziping and moving files, James P. Howard, II |
|---|---|
| Next by Date: | Re: Simple conditional loop, Patrick Burns |
| Previous by Thread: | new installation of S+2000Pro problem with numbers in cells, phguardiol |
| Next by Thread: | Re: Simple conditional loop, Patrick Burns |
| Indexes: | [Date] [Thread] [Top] [All Lists] |