我想总结一下逻辑数据格式。
>test
# A tibble: 17 x 1
test
<lgl>
1 NA
2 FALSE
3 FALSE
4 FALSE
5 FALSE
6 FALSE
7 FALSE
8 FALSE
9 TRUE
10 FALSE
11 FALSE
12 FALSE
13 FALSE
14 FALSE
15 FALSE
将其添加到摘要功能中可用于检查NA
> test %>% summarise(sum(is.na(test)))
# A tibble: 1 x 1
`sum(is.na(test))`
<int>
1 1
但是我无法将其用于测试FALSE或TRUE
> test %>% summarise(sum(test==TRUE))
# A tibble: 1 x 1
`sum(test == TRUE)`
<int>
1 NA
> test %>% summarise(sum(test==FALSE))
# A tibble: 1 x 1
`sum(test == FALSE)`
<int>
1 NA
答案 0 :(得分:0)
这是因为NA是求和的一部分。
Hadley Wickham在这里https://github.com/tidyverse/dplyr/issues/539建议修复该问题
test %>% filter(!is.na(test)) %>% summarise(sum(test==FALSE))
# A tibble: 1 x 1
`sum(test == FALSE)`
<int>
1 15
我希望这可以节省其他人的时间!