0

I have a dataset with transactions made from 2018/07/01 to 2019/06/30 and I want to find how many unique dates are in the "DATE" column (it has over 260k rows, so a date can be repeated several times).

I have tried the following but it just lists all the dates contained in the "DATE" column:

numberofdates <- dplyr::summarize(transactionData, DATE)

Thanks for your help!

AbetR
  • 5
  • 3

2 Answers2

0

Try one of these approaches:

In dplyr:

library(dplyr)
#Code 1
numberofdates <- transactionData %>% summarize(n_distinct(DATE))

Or in base R:

#Code 2
length(unique(transactionData$DATE))
Duck
  • 39,058
  • 13
  • 42
  • 84
0

With data.table we can use

 library(data.table)
 numberofdates <- uniqueN(transactionData$DATE)
akrun
  • 874,273
  • 37
  • 540
  • 662