Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISOWEEK and ISOYEAR options for Floor/Ceil/Round #293

Open
datalove opened this issue Dec 31, 2014 · 3 comments
Open

ISOWEEK and ISOYEAR options for Floor/Ceil/Round #293

datalove opened this issue Dec 31, 2014 · 3 comments
Labels
clock feature a feature request or enhancement

Comments

@datalove
Copy link
Contributor

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!

@vspinu
Copy link
Member

vspinu commented Dec 31, 2014

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

Yes. Of course. Thanks.

@vspinu
Copy link
Member

vspinu commented May 1, 2015

Related #268

@hadley hadley added feature a feature request or enhancement and removed enhancement labels Nov 19, 2019
@DavisVaughan
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clock feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants