【发布时间】:2022-07-11 21:59:50
【问题描述】:
我有这个数据框:
df <- tibble(id = c(1, 2, 3), c_1 = c(T, T, F), c_2 = c(F, F, T)) %>% group_by(id)
# A tibble: 3 x 3
id c_1 c_2
<dbl> <lgl> <lgl>
1 1 TRUE FALSE
2 2 TRUE FALSE
3 3 FALSE TRUE
我现在想计算以c_ 开头的列的行逻辑或
我试过了
df %>% mutate(valid = sum(select(matches("^c_")) == 0))
但是我得到了
`matches()` must be used within a *selecting* function.
我该如何解决这个问题?
【问题讨论】:
-
df %>% rowwise() %>% mutate(valid = any(c_across(starts_with("c_"))))怎么样。查看this existing question了解更多详情
标签: r