Message-ID: <A5D35EC1-7824-40D9-99EA-7F42D032689C@xs4all.nl>
Date: 2012-11-30T05:24:38Z
From: Berend Hasselman
Subject: How to subtract the counter i in for loop?
In-Reply-To: <CAE2FW2mtJT1ew4txoC1cPi0Z2n5BbSjE-SBFaDuHKG84_ktfvw@mail.gmail.com>
On 30-11-2012, at 05:47, C W wrote:
> David,
> Your results is,
>
>> samples
>
> [1] 111 NA 111 NA 111 NA 111 NA 111 NA
> It still has NA's in it. I want it look like this,
>
>> samples
>
> [1] 111 111 111 111 111
You don't need the for loop at all.
samples <- x[x<200]
or
samples <- x[which(x<200)]
Your for loop should look something like this
k <- 1
for(i in 1:10){
if(x[i]<200){
samples[k] <- x[i]
k <- k+1
}
}
na.omit(samples)
Berend