-1
我有一個表,其中我有一個整數的正值和負值的數值列。我想運行一個簡單的if語句,其中如果YDS的值小於10,則一個全新的數字列(Ydsle10)得到一個1,否則爲0簡單如果語句返回「條件有長度> 1」錯誤
這裏是我的代碼:
Data$Ydslt10 <- if(Data$Yds < 10) {Data$Ydslt10 <- 1} else {Data$Ydslt10<-0}
以下是錯誤:
the condition has length > 1 and only the first element will be used
我的表str是:
$ Name : Factor w/ 206 levels "A.Abdullah","A.Boldin",..: 68 199 79 120 120 79 68 27 68 150 ...
$ Team : Factor w/ 31 levels "ARI","BAL","BUF",..: 9 9 9 4 4 9 9 9 9 4 ...
$ Position : Factor w/ 3 levels "RB","TE","WR": 3 2 3 3 3 3 3 1 3 1 ...
$ Yds : num 0 10 4 17 14 14 7 2 6 -3 ...
$ Receptions: num 1 1 1 1 1 1 1 1 1 1 ...
$ Targets : num 1 1 1 1 1 1 1 1 1 1 ...
$ Ydslt10 : num 1 1 1 1 1 1 1 1 1 1 ...
$ Ydsgt10 : num 0 0 0 0 0 0 0 0 0 0 ...
我似乎無法找出個錯誤和網絡搜索沒有太大的幫助。
你真正做到「有長度> 1,只有第一個元素將被使用的條件」的搜索?所以有很多問題和答案。 –
谷歌對我來說第二個結果 - http://stackoverflow.com/questions/14170778/interpreting-condition-has-length-1-warning-from-if-function – thelatemail
老實說,這也是審查人員的錯'這個問題,而不是將其標記爲重複。但是,是的,通常建議在發佈問題時遵循以下指南:http://stackoverflow.com/help/how-to-ask –