我有一個 csv 檔案,我想獲得一個專門的輸出,只需輸入一個字母的 ID (PIPAPNr),例如 input = PIPAP1147
輸出羅杰·納達爾 11.07.1993
Pipapnr="PIPAP1147"
for (i in 1:nrow(Patienten)){
if (Patienten$PIPAP.Nr.==Pipapnr)
DOB<- (Patienten$Geburtsdatum[i])
Name<- (Patienten$Name[i])}
錯誤是
In if (Patienten$PIPAP.Nr. == Pipapnr) DOB <- (Patienten$Geburtsdatum[i]) :
the condition has length > 1 and only the first element will be used
uj5u.com熱心網友回復:
在 if (Patienten$PIPAP.Nr. == Pipapnr) DOB <- (Patienten$Geburtsdatum[i]) 中:條件長度 > 1 并且僅使用第一個元素
在這段代碼Pipapnr中只包含一個值,但Patienten$PIPAP.Nr.可能包含很多值,所以有很多比較,只使用第一個。
這就是錯誤資訊的解釋。可能您希望該if子句讀作if (Patienten$PIPAP.Nr.[i]==Pipapnr) ...
盡管如此,John Garland 在他的評論中是對的,這些事情可以在 R 中更優雅地處理。也許像which(Patienten$PIPAP.Nr.==Pipapnr?
當您的代碼閱讀德語時,也許您對位于http://forum.r-statistik.de的德語 R 論壇感興趣?
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/477566.html
上一篇:用每個客戶的平均值替換零
下一篇:使用帶有for回圈c 的類n次
