Re: [R] problem with using seq() or rep() inside a for loop

2015-07-07 Thread Boris Steipe
The fact that it works when you pass your i values "by hand" should alert you that perhaps your loop control does not do what you think it does. Consider: Your version: for(i in 1:6 - 1) What you probably meant: for(i in 1:(6 - 1)) print(i) The error is created on the first iteration of your l

Re: [R] problem with using seq() or rep() inside a for loop

2015-07-07 Thread William Dunlap
for (i in 1:(ncol(MD_dist) - 1)){ ... } Even better, replace 1:(n-1) with seq_len(n-1) The latter does what you want (and empty integer vector) when n is 1; the former would give c(1,0). Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Jul 7, 2015 at 2:11 PM, David Barron wr

Re: [R] problem with using seq() or rep() inside a for loop

2015-07-07 Thread David Barron
You need to put the expression on the right of the colon in your for statement in parenthesis: for (i in 1:(ncol(MD_dist) - 1)){ ... } On 7 July 2015 at 19:00, Karl Schilling wrote: > Dear All: > > I want to use seq() inside a for-loop and use the looping counter i as the > "by" argument in seq(

[R] problem with using seq() or rep() inside a for loop

2015-07-07 Thread Karl Schilling
Dear All: I want to use seq() inside a for-loop and use the looping counter i as the "by" argument in seq(). Here is some exemplary data and code: # set up some data distances <- c(0, NA, NA, NA, NA, NA, 5, 0, NA, NA, NA, NA, 5, 2, 0, NA, NA, NA, 18