0

My data looks something like this:

set.seed(3162016)
df1 <- data.frame(id=sample(letters, 10000, replace = T), 
                  group1=sample(1:2, 10000, replace = T), 
                  group2=sample(100:101, 10000, replace = T))

I want to create a table with the number of unique id for each combination of group1and group2.

I'm able to the the count with this code:

df1 %>% group_by(group1, group2) %>% summarise(n=n())

or I can get the unique count that I want for a given group with this

df1 %>% filter(group1 == 1, group2 == 100) %>% distinct() %>% nrow()

Alas, I'm not sure how to create the table that I want. I guess I could create my own function, but i'm hopping there is an easier way.

Ignacio
  • 7,646
  • 16
  • 60
  • 113

0 Answers0