質問

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.

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top