Reputation: 85
a <- c(1,1,1,2,3,3,3,3)
b <- c(no,no,no,yes,yes,yes,yes,yes)
data.frame(a,b)
The question is how to use group_by to make someting like this?
no 1
yes 2
Upvotes: 0
Views: 43
Reputation: 101343
Do you mean this?
> df %>%
+ group_by(b) %>%
+ summarise(n = n_distinct(a))
# A tibble: 2 x 2
b n
<chr> <int>
1 no 1
2 yes 2
Upvotes: 0