Group unique R studio values

I have a database with the following fields:

NUM_PROPOSTA DATA_PROPOSTA
7911334 2021-08-25
7911334 2021-08-25
7911340 2021-08-25
7911340 2021-08-25

I want to make a separate count in RStudio that only group by day, but also unite the numbers of the proposals. But when I do it looks like this:

base_serasa_pj %>% 
  group_by(NUM_PROPOSTA) %>% 
  count(DATA_PROPOSTA)
NUM_PROPOSTA DATA_PROPOSTA N
7911334 2021-08-25 9
7911334 2021-08-25 8
7911360 2021-08-25 1
7911369 2021-08-25 8

It is only grouping the number of proposals, I’ve already tried to do it with count too, but it gives the same result on days. The result I expect is:

NUM_PROPOSTA DATA_PROPOSTA N
7911334 2021-08-25 4

Because on 25-08-2021 we only had 4 different proposals.

These numbers 9, 8, 1 and 8 occur because each proposal was sent that number of times that day, but for the purpose of what I need they need to be counted only once a day regardless of how many times it is repeated on the same day.

Can anyone help me?

Thanks

Hi !

If you need the number of proposals by day, the grouping variable is DATA_PROPOSTA. Try this:

base_serasa_pj %>% 
  count(DATA_PROPOSTA)

PS: you don’t need to group_by() before count(), because count() already create groups.

1 curtida

Hello Beatriz!!

So this way it still sums doubled. Example on 08/25/2021, a total of four proposals would have to occur, but 26 appear.
Because he is adding up the number of times the same thing is repeated on the same day.

I don’t know if I was specific hahah

Beatriz, me here again haha

This way worked!!!

base_serasa_pj %>%   
  group_by(DATA_PROPOSTA) %>%   
  summarise(N = n_distinct(NUM_PROPOSTA))
1 curtida