我对失败背后的逻辑感兴趣。如果我在分组数据框中向
dplyr::filter
提供布尔向量,则该布尔向量是否应用于每个组?
示例:
tibble(
group = c("a", "a", "b"),
value = c(1, 1, 2)
) %>%
group_by(group) %>%
dplyr::filter(c(TRUE, TRUE, FALSE))
---
Output:
Error in `dplyr::filter()`:
ℹ In argument: `c(TRUE, TRUE, FALSE)`.
ℹ In group 1: `group = "a"`.
Caused by error:
! `..1` must be of size 2 or 1, not size 3.
Backtrace:
1. ... %>% dplyr::filter(c(TRUE, TRUE, FALSE))
9. dplyr:::dplyr_internal_error(...)
a
你只有2个条目,而不是3个(作为你的布尔向量)