Re: [R] seq_len and loops

2014-01-02 Thread Göran Broström
tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Göran Broström Sent: Tuesday, December 31, 2013 4:10 PM To: r-help@R-project.org Subject: Re: [R] seq_len and loops Thanks for the answers from Duncan, Bill, Gabor, and Henrik. Y

Re: [R] seq_len and loops

2014-01-01 Thread William Dunlap
; On 12/22/2013 06:57 PM, William Dunlap wrote: > >>> for (i in seq_len(x - 1) + 1) > >>> > >>> should be efficient and safe. > >> > >> Oops, not safe when x is 0. > > > > Also, the '+ 1' should be '+ 1L' to get the

Re: [R] seq_len and loops

2013-12-31 Thread Göran Broström
.@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan Murdoch Sent: Saturday, December 21, 2013 3:52 PM To: Göran Broström; R-help@r-project.org Subject: Re: [R] seq_len and loops On 13-12-21 6:50 PM, Duncan Murdoch wrote: On 13-12-21 5:57 PM, Göran Broström wrote: I was rec

Re: [R] seq_len and loops

2013-12-22 Thread William Dunlap
-Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Duncan Murdoch > Sent: Saturday, December 21, 2013 3:52 PM > To: Göran Broström; R-help@r-project.org > Subject: Re: [R] seq_len and loops > > On 13-12-21 6:50

Re: [R] seq_len and loops

2013-12-21 Thread Henrik Bengtsson
What about seq_len2 <- function(length.out, from=1L) { seq(from=from, length.out=max(0L, length.out-from+1L)) } > lapply(0:4, FUN=seq_len2, from=2L) [[1]] integer(0) [[2]] integer(0) [[3]] [1] 2 [[4]] [1] 2 3 [[5]] [1] 2 3 4 /Henrik On Sat, Dec 21, 2013 at 2:57 PM, Göran Broström wrote: > I

Re: [R] seq_len and loops

2013-12-21 Thread Duncan Murdoch
On 13-12-21 6:50 PM, Duncan Murdoch wrote: On 13-12-21 5:57 PM, Göran Broström wrote: I was recently reminded on this list that "Using 1:ncol() is bad practice (seq_len is designed for that purpose)" (Ripley) This triggers the following question: What is "good practice" for 2:ncol(x)? (This is

Re: [R] seq_len and loops

2013-12-21 Thread Duncan Murdoch
On 13-12-21 5:57 PM, Göran Broström wrote: I was recently reminded on this list that "Using 1:ncol() is bad practice (seq_len is designed for that purpose)" (Ripley) This triggers the following question: What is "good practice" for 2:ncol(x)? (This is not a joke; in a recursive situation it oft