[R] for loop

David Winsemius dwinsemius at comcast.net
Sat Sep 11 14:48:28 CEST 2010


On Sep 11, 2010, at 8:39 AM, Peng, C wrote:

>
> or:
>
> k=0
> for (i in 1:k) if(k>0) print(i)

Because of the way the ":" operator works, I would have tested k >=1

 > k=0.5
 > for (i in 1:k) if (k>0){print(i)}
[1] 1

But Gabor's suggestion to use seq_len(k) is cleaner, anyway.

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list