使用 for 循环的专用输出
Specialized output with for loop
我有一个 csv 文件,我想得到一个专门的输出,只需输入字母的 ID (PIPAPNr)
例如
输入 = 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
In if (Patienten$PIPAP.Nr. == Pipapnr) DOB <- (Patienten$Geburtsdatum[i]) :
the condition has length > 1 and only the first element will be used
在这段代码中 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 论坛感兴趣?
我有一个 csv 文件,我想得到一个专门的输出,只需输入字母的 ID (PIPAPNr) 例如 输入 = 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
In if (Patienten$PIPAP.Nr. == Pipapnr) DOB <- (Patienten$Geburtsdatum[i]) : the condition has length > 1 and only the first element will be used
在这段代码中 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 论坛感兴趣?