我有一个表,每行都有一个名为example2 <- example[, 1, drop = FALSE]
# reason_code
# 1 d_01, d_03
# 2 d_01
# 3 d_02
# 4 d_02, d_03
library(dplyr)
library(tidyr)
example3 <- example2 %>% mutate(ID = 1:n())
example4 <- example3 %>%
left_join(example3 %>%
separate_rows(reason_code, sep = ", ") %>%
mutate(Flag = TRUE) %>%
spread(reason_code, Flag, fill = FALSE),
by = "ID") %>%
select(-ID)
example4
# reason_code d_01 d_02 d_03
# 1 d_01, d_03 TRUE FALSE TRUE
# 2 d_01 TRUE FALSE FALSE
# 3 d_02 FALSE TRUE FALSE
# 4 d_02, d_03 FALSE TRUE TRUE
的属性,我需要找到表中主要使用的CompanyId
。
示例:
CompanyId
如何在表格中找到23?
[id = 1 , CompanyID = 23]
[id = 2 , CompanyID = 10]
[id = 3 , CompanyID = 10]
[id = 4 , CompanyID = 11]
[id = 5 , CompanyID = 23]
[id = 6 , CompanyID = 23]
[id = 7 , CompanyID = 23]
答案 0 :(得分:3)
index >= 0