cut(date_var, breaks='week', start.on.monday = F)
This works for me. It is available in the r database and should be faster. Breaks can be used to search for the beginning of the day, week, month, quarter, year.
To read? Cut and? Cut. the date
Sys.Date()
[1] "2017-12-23"
cut(Sys.Date(), breaks = 'week', start.on.monday = F)
[1] 2017-12-17 Levels: 2017-12-17
cut(Sys.Date(), breaks = 'month')
[1] 2017-12-01 levels: 2017-12-01
cut(Sys.Date(), breaks = 'quarter')
[1] 2017-10-01 levels: 2017-10-01
cut(Sys.Date(), breaks = 'year')
[1] 2017-01-01 Levels: 2017-01-01
source share