[R] Using seq_len() vs 1:n

Bert Gunter gunter.berton at gene.com
Thu Feb 11 22:49:47 CET 2010


" I like to use 1:n when I'm teaching debugging, because it looks so safe 
but isn't."

Duncan Murdoch
----------------
... operator precedence providing lots of examples, e.g.

> 1: 2*3
[1] 3 6

## vs

> seq_len(2*3)
[1] 1 2 3 4 5 6

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics
 
 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Duncan Murdoch
Sent: Thursday, February 11, 2010 1:41 PM
To: Peter Ehlers
Cc: r-help at r-project.org
Subject: Re: [R] Using seq_len() vs 1:n

On 11/02/2010 3:39 PM, Peter Ehlers wrote:
> R-people,
>
> Duncan Murdoch's response in
>
>   https://stat.ethz.ch/pipermail/r-help/2010-February/227869.html
>
> reminded me of something I had been meaning to ask.
>
> A while ago I started using
>
>   for(i in seq_len(v)) {....}
>
> in preference to
>
>   for(i in 1:n) {....}
>
> Duncan's post shows that if n can be zero, there is
> an advantage to using seq_len.
> Is there ever a *dis*advantage?

I like to use 1:n when I'm teaching debugging, because it looks so safe 
but isn't.

Duncan Murdoch

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list