我已经看过了,但我只是不明白为什么我会收到此错误。我想根据CN列中的整数值在CNSTATUS中分配一个数字。如果小于10,则CNSTATUS应该为10;如果10到20之间的CNSTATUS shuold为2,如果大于20,则应该为3
CN是整数列
我的数据框
CN CNSTATUS
2
12
43
2
4
我的代码:
if(OCCAMSdbTumCN$CN < 10) {
OCCAMSdbTumCN$CNSTATUS <- 1
}
else if(OCCAMSdbTumCN$CN > 10 & OCCAMSdbTumCN$CN<20) {
OCCAMSdbTumCN$CNSTATUS <- 2
}
else{
OCCAMSdbTumCN$CNSTATUS <- 2}
The error I am getting is
In if (OCCAMSdbTumCN$CN < 10) { :
the condition has length > 1 and only the first element will be used
您会想要这样的东西:
OCCAMSdbTumCN$CSTATUS <- ifelse(OCCAMSdbTumCN$CN < 10, 1, ifelse(OCCAMSdbTumCN$CN >= 10 & OCCAMSdbTumCN$CN < 20, 2, 3))
玩等于或大于或等于所需的游戏。请注意,在您的示例中,案例10和案例20直到结束都不会被发现。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句