Do NOT use 1:length(x) in *for* statement in R.

Because when x is empty, the loop will run over 1:0, which is twice.

> y <- as.numeric() > length(y) [1] 0 > for (i in 1:length(y)) { print("y")} [1] "y" [1] "y" > for (i in 1:seq(along=y)) { print("y")} Error in 1:seq(along = y) : argument of length 0

Do NOT use 1 length x in for…