Duncan Murdoch <murdoch.dun...@gmail.com> writes: >> for ( i in 1:length(var1)){ > > This is generally a bad idea: if length(var1) == 0, it does the wrong > thing, since 1:0 is c(1L, 0L). Better to use > > for ( i in seq_along(var1) ) { >
granted. One should check the validity of their variables before using them but I argue that seq_along does not protect you from the unexpected behaviour. If the length of var1 should not be 0 so stopifnot(length(var)==0) for ( i in 1:length(var1)){ elem1 <-var1[i] elem2 <- var2[i] } ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.