I have a dataframe where one of the columns contains dates (some dates appear multiple times). I want to aggregate the dates by week. The best way I can think of this is to
With lubridate
you could try this:
library(lubridate)
dates <- seq.Date(as.Date("2016-04-04"), as.Date("2016-04-14"), by = 1)
floor_date(dates - 1, "weeks") + 1
floor_date
starts weeks on Sundays, so to avoid those being included in the next week you have to subtract one before rounding and then increase the value by one day.