【发布时间】:2018-04-06 13:12:18
【问题描述】:
当我输入这些代码时,
z<-NULL
for(i in unique(A$KCL_ID)){
RESULT<-A[A$KCL_ID==i,]
if(RESULT$DAYS==min(RESULT$DAYS)){
RESULT$DATE<-"closest"
}else{RESULT$DATE<-RESULT$BMIextraction}
z<-rbind(z,RESULT)
}
我收到一些类似这样的错误消息:
Error in charToDate(x) :
character string is not in a standard unambiguous format
In addition: Warning messages:
1: In if (RESULT$DAYS == min(RESULT$DAYS)) { :
the condition has length > 1 and only the first element will be used
2: In if (RESULT$DAYS == min(RESULT$DAYS)) { :
the condition has length > 1 and only the first element will be used
3: In if (RESULT$DAYS == min(RESULT$DAYS)) { :
the condition has length > 1 and only the first element will be used
4: In if (RESULT$DAYS == min(RESULT$DAYS)) { :
the condition has length > 1 and only the first element will be used
我该如何解决这个问题?
【问题讨论】:
-
if需要一个逻辑标量;也许您正在寻找矢量化的ifelse? -
阅读
help("if")应该可以帮助您解决问题。
标签: r for-loop if-statement