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 =
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
stevelavr...@hotmail.com wrote:
Everyone,
I'm very new
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 comes to
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){
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 in 2
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) {
num[i] -
: [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
num - rep(0,10
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
To: Steve Lavrenz
Cc: r-help@r-project.org
Subject: Re: [R] Creating a loop with an indefinite end term
Here are a couple
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
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
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
-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
please
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 at all?
Will this do
13 matches
Mail list logo