【发布时间】:2018-09-16 13:45:16
【问题描述】:
我正在使用这个双重条件在新列中获取输出,但它只给我第一个匹配项,而不是所有匹配条件。 在“scores2”列的第三和第四行中,必须是 0,2 而不是 0。 如果有人可以帮助我,那就太好了。 提前非常感谢。
id touchpoint_ts tp_type Referrer scores scores2
1 31.10.2017 05:09 a 4 1,7 0
1 13.10.2017 03:19 b 2 0,1 0,2
1 12.10.2017 06:19 b 2 0,1 0
1 12.10.2017 06:19 b 2 0,1 0
1 12.10.2017 06:19 b 0 0,1 0
1 08.09.2017 14:26 a 3 3 0
dataset$scores2<-c(0)
for (i in 1:length(dataset$id)){
if (dataset$tp_type[i] == "b"){
while ((dataset$Referrer[i]) > 1){
dataset$scores2[i]=dataset$scores[i]*2
} } else {
dataset$scores2[i]=0
}
}
【问题讨论】:
标签: r loops if-statement while-loop conditional-statements