Open datalove opened 9 years ago
Happy to work on this if it's a good idea!
Yes. Of course. Thanks.
Related #268
You can do this with clock's iso-year-week-day calendar type
library(clock)
library(magrittr)
ywd <- year_month_day(2016, 1, 2) %>%
as_iso_year_week_day()
ywd
#> <iso_year_week_day<day>[1]>
#> [1] "2015-W53-6"
# Grouping by the ISO week component
ywd %>%
calendar_group("week", n = 1) %>%
calendar_widen("day") %>%
as.Date()
#> [1] "2015-12-28"
# Grouping by the ISO year component
ywd %>%
calendar_group("year", n = 1) %>%
calendar_widen("day") %>%
as.Date()
#> [1] "2014-12-29"
# Setting components
set_week(ywd, 2)
#> <iso_year_week_day<day>[1]>
#> [1] "2015-W02-6"
set_year(ywd, 2017)
#> <iso_year_week_day<day>[1]>
#> [1] "2017-W53-6"
Created on 2021-05-25 by the reprex package (v1.0.0)
https://clock.r-lib.org/reference/index.html#section-iso-year-week-day
Now that we have both
isoyear
andisoweek
, it would be good to include them as options forfloor_date
,ceil_date
andround_date
.For example:
floor(ymd('2016-01-02'),'isoweek')
is2015-12-28
floor(ymd('2016-01-02'),'isoyear')
is2014-12-29
Will need to create assignment functions for
isoweek<-
andisoyear<-
.Happy to work on this if it's a good idea!