On Nov 29, 2012, at 3:25 PM, C W wrote: > I want to fill up vector a with vector b.
Vector "a"? Vector "b"? > The condition is: b<200, otherwise don't fill it up. That would seem to be the current behavior, subject of course to an agreed upon definition for "filling up". It's possible , even likely, that you can get what you want with no loop at all. samples[ x < 200 ] <- x[ x <200 ] -- David. > Mike > > On Thu, Nov 29, 2012 at 6:11 PM, David Winsemius <dwinsem...@comcast.net> > wrote: > > On Nov 29, 2012, at 1:55 PM, C W wrote: > > > Hi list, > > I am writing a for loop that looks like this: > > samples<-rep(NA,10) > > x <- rep(c(111, 225), 5) > > for(i in 1:10){ > > If(x[i]<200){ > > samples[i] <- x[i] > > }else{ > > i=i-1 > > If you expected the else clause to assign something to the samples vector, > you are mistaken. > > > } > > } > > > > The problem is that the returning vector still contains NA, I think the i > > in "else" is not getting subtracted. How should I get it to work? > > You could start by telling us what you wanted to happen. You can change the > index of a for loop inside the body, but it will not "back up the process" > since at the end of the loop the next "i" will not depend on what you changed > it to inside the loop. > > -- > > David Winsemius, MD > Alameda, CA, USA > > David Winsemius, MD Alameda, CA, USA [[alternative HTML version deleted]] ______________________________________________ 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.