Skip to content
Prev 312438 / 398506 Next

How to subtract the counter i in for loop?

On 30-11-2012, at 05:47, C W wrote:

            
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