[R] for loop
Gabor Grothendieck
ggrothendieck at gmail.com
Sat Sep 11 14:33:02 CEST 2010
On Sat, Sep 11, 2010 at 4:39 AM, Yuan Jian <jayuan2008 at yahoo.com> wrote:
> Hello,
> I have a simple question: I want to list numbers 1:k, but if k <1, I hope nothing listed.
> how should we do?
> k=2
> for (i in 1:k) print(i)
> [1] 1 # <-correct
> [1] 2
> k=0
> for (i in 1:k) print(i)
> [1] 1 #<---- wrong
> [1] 0
>
Try:
k <- 0
for (i in seq_len(k)) print(i)
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list