x = 0
while (x <= 100){
x = x + sample(1:6,1,replace = F)
ladder.bottom = c(1,4,9,21,28,36,51,80)
ladder.top = c(38,14,31,42,84,44,67,100)
chute.bottom = c(6,11,19,24,26,53,60,73,75,78)
chute.top = c(16,49,62,87,47,56,64,93,95,98)
w = which(ladder.bottom == x)
t = which(chute.top == x)
if (length(w) >= 0){
x = ladder.top[w]
print(x)
}else if (length(t) >= 0){
x = chute.bottom[t]
print(x)
}else {
print(x)
next
}
}
返回
[1] 14 numeric(0) Error in while (x <= 100) { : argument is of length zero
和我不知道为什么
在if (length(w) >= 0)
和else if (length(t) >= 0)
中,将>=
替换为>