正常情況下對X的循環(huán)不會出錯
> x<-c(11,22,33,44,55,66,77)
> for(i in 1:length(x)){print(x[i])}
[1] 11
[1] 22
[1] 33
[1] 44
[1] 55
[1] 66
[1] 77```
###當y是空向量循環(huán)會出錯
y<-c()
for(i in 1:length(y)){print(y[i])}
NULL
NULL```
使用seq函數(shù)則不會出錯
for(i in seq(y)){print(y[i])}
seq對正常情況也能處理
> for(i in seq(x)){print(x[i])}#效果和使用length相同
[1] 11
[1] 22
[1] 33
[1] 44
[1] 55
[1] 66
[1] 77```