0

I have a DF called Base that looks like this:

Treatment Gender ID
1 M A
1 F B
1 F B
1 F E
2 M A
2 F B
2 M C
2 M C
2 M D

And I would like to count by Treatment and Gender the number of distinct IDs, I have and get it in another dataframe, so I would have a DF called Uniques that would look like this:

Treatment Gender ID
1 M 1
1 F 2
2 M 3
2 F 1

I have tried to write this:

Uniques = Base %>% group_by(Treatment, Gender) %>% summarise(count = n_distinct(Base$ID))

But I get the following error:

`summarise()` regrouping output by 'Treatment' (override with `.groups` argument)

What is wrong and how could I fix it?

Thank you

Nnatee
  • 31
  • 2
  • It is not an error, but just a friendly warning. You may check [here](https://stackoverflow.com/questions/62140483/how-to-interpret-dplyr-message-summarise-regrouping-output-by-x-override/62140681#62140681) – akrun Apr 04 '21 at 19:27
  • 1
    Also, there is an issue in `Base$`. It shsould be just `n_distinct(ID))`. `Base$` will select the entire column and thus gets the same value – akrun Apr 04 '21 at 19:28
  • your code works fine. – Arslan Sh. Apr 04 '21 at 19:42
  • Thank you so much Akrun! – Nnatee Apr 04 '21 at 19:54

0 Answers0