需要了解如何修复此过滤逻辑。
test.session <- c("A","A","A","B","B","B")
test.start_flag <- c("1","0","0","1","0","0")
test.url <- c("in_list","in_field","out","not_in_list","in_field","out")
test.code_map <- 'tbd'
test.manual_map <- c("1","1","0","0","0","0")
test.df <- data.frame(test.session, test.start_flag, test.url, test.code_map, test.manual_map)
我想生成test.code_map
以匹配test.manual_map
向量。我编写了前四行,但逻辑需要针对第5行和第6行进行调整。逻辑:
***此字段需要等于0,因为在此特定会话(会话B)中,起始URL不等于我定义的字段,因此code_map的所有值都必须等于0只有在满足这一特定条件时才会这样做。
答案 0 :(得分:0)
理解你想要的东西有点令人困惑,但似乎测试会话有一个test.url&#34; not_in_list&#34;,那么该测试会话的所有test.code_maps应该是0.如果是这样,这应该有效
test.df$test.code_map<-ifelse(
((test.df$test.start_flag == 1 & test.df$test.url=="in_list")|
(test.df$test.start_flag == 0 & test.df$test.url=="in_field"& test.df$test.session!="B") &
!test.session %in% test.df$test.session[test.df$test.url=="not_in_list"]),
1, 0)