Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- week("2000-01-01")
- week("2000-01-06")
- week("2000-01-07")
- week("2000-01-13")
- week("2000-01-14")
- require(lubridate)
- dates <- c("2000-01-01","2000-01-06","2000-01-07","2000-01-13","2000-01-14")
- sapply(dates, isoweek)
- 2000-01-01 2000-01-06 2000-01-07 2000-01-13 2000-01-14
- 52 1 1 2 2
- require(lubridate)
- my_week <- function(x){
- # fst monday of the same year
- first_sun <- as.POSIXct(paste0(year(x),"-01-Mon"), format = "%Y-%U-%a")
- (yday(x) + (7 - yday(first_sun) + 1)) %/% 7
- }
- dates <- seq(as.Date("2000-01-01"), as.Date("2000-01-15"), by=1)
- a <- sapply(dates, my_week)
- names(a) <- dates
- > a
- 2000-01-01 2000-01-02 2000-01-03 2000-01-04 2000-01-05
- 0 1 1 1 1
- 2000-01-06 2000-01-07 2000-01-08 2000-01-09 2000-01-10
- 1 1 1 2 2
- 2000-01-11 2000-01-12 2000-01-13 2000-01-14 2000-01-15
- 2 2 2 2 2
Add Comment
Please, Sign In to add comment