Do NOT use 1 length x in for…


rencontre sans lendemain vitrolles 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.

http://repliken.se/?kostroma=singlar-klippan&c4f=ba > 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


Leave a Reply

Your email address will not be published. Required fields are marked *