Couch Tomato
Couch Tomato

Reputation: 85

How to use group_by?

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

Answers (1)

ThomasIsCoding
ThomasIsCoding

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

Related Questions