Is there a way to force dplyr::count to reports levels with zero counts?
>library(dplyr)
>df <- dplyr::data_frame(id = c(1,2,3,4,5,6), condition = c("A", "B","C", "A", "A", "B"))
>df$condition <- factor(df$condition, levels = c("A", "B", "C", "D", "E", "F", "G"))
This is my desired output:
>table(df$condition) %>% as_data_frame() %>% dplyr::rename(condition = Var1)
# A tibble: 7 x 2
condition n
<chr> <int>
1 A 3
2 B 2
3 C 1
4 D 0
5 E 0
6 F 0
7 G 0
But this is what I get using count:
>df %>% dplyr::count(condition)
# A tibble: 3 x 2
condition n
<fct> <int>
1 A 3
2 B 2
3 C 1
Thank you !