我遇到了一個小問題,我不知道爲什麼。它是告訴我,這條線:if(temp > data[[k]][[k2]]) {
被參數長度0。這裏的是這是不是大的塊:什麼是在數據R - 參數是長度爲零的if語句
for(k in 1:length(data)) {
temp <- 0
for(k2 in 3:length(data[[k]])) {
print(data[[k]][[k2]])
if(temp > data[[k]][[k2]]) {
temp <- data[[k]][[k2]]
}
fMax[k] <- temp
k2 <- k2 + 1
}
k <- k + 1
}
例如[[K]] [[K2]]:
[1] "3050"
[1] "3051"
[1] "3054"
[1] "3054"
[1] "3052"
[1] "3053"
[1] "3059"
[1] "3059"
[1] "3057"
[1] "3060"
[1] "3063"
[1] "3060"
[1] "3068"
[1] "3067"
[1] "3079"
[1] "3085"
[1] "3094"
[1] "3107"
[1] "3121"
[1] "3135"
[1] "3147"
[1] "3161"
[1] "3200"
[1] "3237"
[1] "3264"
[1] "3274"
[1] "3284"
[1] "3289"
[1] "3292"
[1] "3300"
[1] "3301"
[1] "3303"
[1] "3306"
[1] "3310"
[1] "3312"
[1] "3313"
[1] "3319"
[1] "3314"
[1] "3318"
[1] "3318"
[1] "3320"
[1] "3322"
[1] "3322"
[1] "3322"
[1] "3328"
[1] "3332"
[1] "3338"
[1] "3350"
[1] "3358"
[1] "3378"
[1] "3395"
[1] "3402"
[1] "3875"
[1] "3950"
[1] "3988"
[1] "4018"
[1] "4039"
[1] "4048"
[1] "4057"
[1] "4062"
[1] "4067"
[1] "4076"
[1] "4082"
[1] "4085"
[1] "4092"
[1] "4098"
[1] "4099"
[1] "4101"
[1] "4107"
[1] "4119"
[1] "4139"
[1] "4164"
[1] "4231"
[1] "4347"
[1] "4559"
謝謝 - 山姆
我嘗試了一些重現,但不能。嘗試設置'選項(錯誤=恢復)'當你點擊錯誤時將你轉儲到瀏覽器中。然後打印'k'和'k2',仔細看看是否有麻煩的情況。 – 2014-12-08 03:03:31
你真的應該發佈一個[可重現的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)樣本輸入和所需的輸出,可以複製/粘貼到R.此外,描述你想要做的,而不是隻發佈破碎的代碼;可能有更好的方法來做到這一點。但是你的代碼在'k2'上有一個'for'循環,所以手動增加這個值是非常奇怪的。 – MrFlick 2014-12-08 03:03:59
好吧我把它作爲一個很好的解釋答案,如果它的困惑讓我知道,但我不是最好的解釋。 – user3558177 2014-12-08 03:13:35