lubridate icon indicating copy to clipboard operation
lubridate copied to clipboard

ISOWEEK and ISOYEAR options for Floor/Ceil/Round

Open datalove opened this issue 10 years ago • 3 comments

Now that we have both isoyear and isoweek, it would be good to include them as options for floor_date, ceil_date and round_date.

For example: floor(ymd('2016-01-02'),'isoweek') is 2015-12-28 floor(ymd('2016-01-02'),'isoyear') is 2014-12-29

Will need to create assignment functions for isoweek<- and isoyear<-.

Happy to work on this if it's a good idea!

datalove avatar Dec 31 '14 02:12 datalove

Happy to work on this if it's a good idea!

Yes. Of course. Thanks.

vspinu avatar Dec 31 '14 05:12 vspinu

Related #268

vspinu avatar May 01 '15 10:05 vspinu

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

DavisVaughan avatar May 25 '21 12:05 DavisVaughan