Frage

Do you guys know, how to get the first day of each week within a time interval, using package "lubridate"?

I know I can also generate using "seq.Date", but now that I have generated a time interval and would like to use it with "%within%" later, I would like to just use this interval and get the date of each week from it.

War es hilfreich?

Lösung

library(lubridate)
dates <- seq(Sys.Date() - 100, Sys.Date(), by = "1 days")
week.ids <- floor_date(dates, "week")

Now dates will have each of the last 100 days, and week.ids will have the date of the most recent Sunday before each of the dates in dates. Therefore, the week.ids vector provides the sufficient information to group the dates by week.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top