Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Charilaos Skiadas
-Steve Haris Skiadas Department of Mathematics and Computer Science Hanover College From: Jean V Adams [mailto:jvad...@usgs.gov] Sent: Tuesday, April 10, 2012 12:38 PM To: Steve Lavrenz Cc: r-help@r-project.org Subject: Re: [R] Creating a loop with an indefinite end term Do you need a loop

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread David Winsemius
-project.org Subject: Re: [R] Creating a loop with an indefinite end term Do you need a loop at all? Will this do the trick? seq(from=0, to=100, by=5) Jean Steve Lavrenz wrote on 04/10/2012 09:48:34 AM: Everyone, I'm very new to R, especially when it comes to loops and functions, so p

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Drew Tyre
While you can build up a vector like this in a for loop, this is exactly the sort of construction that leads to excessive memory growth because on each iteration of the loop R creates a new copy of the vector x - old copies have no references to them, but are not deallocated until the next automati

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Steve Lavrenz
From: Jean V Adams [mailto:jvad...@usgs.gov] Sent: Tuesday, April 10, 2012 12:38 PM To: Steve Lavrenz Cc: r-help@r-project.org Subject: Re: [R] Creating a loop with an indefinite end term Do you need a loop at all? Will this do the trick? seq(from=0, to=100, by=5) Jean Steve Lavrenz

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Jean V Adams
Do you need a loop at all? Will this do the trick? seq(from=0, to=100, by=5) Jean Steve Lavrenz wrote on 04/10/2012 09:48:34 AM: > Everyone, > > I'm very new to R, especially when it comes to loops and functions, so > please bear with me if this is an elementary question. I cannot seem to >

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Albyn Jones
y that I can construct this so that my > array is exactly as long as the number of spots I need to reach my threshold > value? > > Thanks, > > -Steve > > -Original Message- > From: Albyn Jones [mailto:jo...@reed.edu] > Sent: Tuesday, April 10, 2012 11:46 AM &g

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread David Winsemius
Re: [R] Creating a loop with an indefinite end term Here are a couple of constructions that work. albyn === num <- rep(0,10) for (i in 2:10) { num[i] <- num[i-1] + 5 if(num[i] > 20) break } num [1] 0 5 10 15 20 25 0 0 0 0 or

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Jessica Streicher
> x<-numeric(1) > x [1] 0 > x[2]<-2 > x [1] 0 2 you don't really need to define the length? Am 10.04.2012 um 17:45 schrieb Albyn Jones: > Here are a couple of constructions that work. > > albyn > === > > num <- rep(0,10) > for (i in 2:10) { >

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Steve Lavrenz
Jones [mailto:jo...@reed.edu] Sent: Tuesday, April 10, 2012 11:46 AM To: Steve Lavrenz Cc: r-help@r-project.org Subject: Re: [R] Creating a loop with an indefinite end term Here are a couple of constructions that work. albyn === num <- rep(0,10) for (i

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Albyn Jones
Here are a couple of constructions that work. albyn === num <- rep(0,10) for (i in 2:10) { num[i] <- num[i-1] + 5 if(num[i] > 20) break } > num [1] 0 5 10 15 20 25 0 0 0 0 or num <- rep(0,10) done <- FALSE i <- 2 while(!done){

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Jessica Streicher
http://cran.r-project.org/doc/manuals/R-lang.html#while i<-2 while(value <=100){ num[i] <- num[i-1] +5 value <- num[i] i <- i+1 } something like this? greetings Jessi Am 10.04.2012 um 16:48 schrieb Steve Lavrenz: > Everyone, > > I'm very new to R, especially when it c

Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread R. Michael Weylandt
You might want to use a while loop instead, something like: while(TRUE){ # Do things # Test: if your condition has occured if(conditionHappened) break # break will end loop. } Michael On Tue, Apr 10, 2012 at 10:48 AM, Steve Lavrenz wrote: > Everyone, > > I'm very new to R, especially when

[R] Creating a loop with an indefinite end term

2012-04-10 Thread Steve Lavrenz
Everyone, I'm very new to R, especially when it comes to loops and functions, so please bear with me if this is an elementary question. I cannot seem to figure out how to construct a loop which runs a function until a certain value is computed. For example, say I have the following: num = numer