Count the number of unique character types based on the date in R


I have a dataframe titled FilteredData with many columns. Specifically, there are two columns I am interested in: Date and Sale number.

I want to group all Sale number entries by dates. Date is a date-type field, and Sale number is a character-type field. If I'm not mistaken, I think these types are the reason why other Q&As on S.O. haven't been much help to me.

How can I do this?

I've tried the following:

aggregate(FilteredData$`Sale number`, by FilteredData$Date, FUN = count)
group_by(FilteredData$`Sale number`, FilteredData$Date)

Neither worked, and neither did the solution found here when I tried it.

I tried the following:

Freq = sqldf('SELECT Date, COUNT('Sale Number') FROM FilteredData GROUP BY Date')

and it surprisingly worked. However, is there a way to obtain this result without having to use SQL syntax, i.e. something "purely" in R?

Your question is a little unclear... So you want to group by date and then count the number of non-duplicate entries within a date?

dplyr can do this:

FilteredData %>% # take filtered data
  group_by(FundedDate) %>% # group by the date
  subset(!duplicated('Sale number')) %>% # remove rows that are duplicated sales numbers
  count('Sale number') # count sales numbers