【发布时间】:2021-01-19 15:50:45
【问题描述】:
我的目标是根据每个测量径流水平(“ q347_2035"),这里是 283 个测量值的向量。所以例如如果 q347_2035 大于 60 且小于/等于 160,则最小径流计算为 q347_2035 的一部分(参见下面的代码):
getQMIN <- if(q347_2035 <= 60){
qMin_2035 = 50
} else if (q347_2035>60 & q347_2035 <= 160) {
qMin_2035 = 50 + (8/10)*(q347_2035 - 60)
} else if (q347_2035>=160 & q347_2035 <= 500) {
qMin_2035 = 130 + (4.4/10)*(q347_2035 - 160)
} else if (q347_2035>=500 & q347_2035 <= 2500) {
qMin_2035 = 280 + (31/100)*(q347_2035 - 500)
} else if (q347_2035>=2500 & q347_2035 < 10000) {
qMin_2035 = 900 + (21.3/100)*(q347_2035 - 2500)
} else if (q347_2035>=10000 & q347_2035 < 60000) {
qMin_2035 = 2500 + (150/1000)*(q347_2035 - 10000)
} else {
qMin_2035 = 10000
}
现在我总是收到错误消息,说:
Warning messages:
1: In if (q347_2035 <= 60) { :
the condition has length > 1 and only the first element will be used
2: In if (q347_2035 > 60 & q347_2035 <= 160) { :
the condition has length > 1 and only the first element will be used
3: In if (q347_2035 >= 160 & q347_2035 <= 500) { :
the condition has length > 1 and only the first element will be used
4: In if (q347_2035 >= 500 & q347_2035 <= 2500) { :
the condition has length > 1 and only the first element will be used
谁能帮忙解决这个问题? 提前非常感谢!
【问题讨论】:
标签: r if-statement