| 1 |
#' Converts date from standard notation to week notation according to ISO 8601 |
| 2 |
#' |
| 3 |
#' This function returns the year, the week of the year, and the day of week of a given date according to ISO 8601. |
| 4 |
#' It is an substitute for the \code{\%Y-W\%V-\%u} format which is not implemented on Windows. |
| 5 |
#' |
| 6 |
#' According to ISO 8601, the year of the week can differ from the calendar year (see the examples). |
| 7 |
#' |
| 8 |
#' @param date Vector which can be coerced to class \code{Date} |
| 9 |
#' @return A character vector of year, week, and weekday in format "\code{\%Y-W\%V-\%u}" |
| 10 |
#' @seealso \code{\link{strptime}} for a description of the date formats and references on ISO 8601. |
| 11 |
#' @export |
| 12 |
#' @author Uwe Block \email{u.block.mz@@googlemail.com} |
| 13 |
#' @examples |
| 14 |
#' x <- paste(1999:2011, "-12-31", sep = "") |
| 15 |
#' y <- as.Date(x) |
| 16 |
#' data.frame(date = format(y), weekdate = date2ISOweek(y)) |
| 17 |
#' data.frame(date = x, weekdate = date2ISOweek(x)) |
| 18 |
date2ISOweek <- function(date) { |
| 19 |
return(ifelse(is.na(date), NA_character_, paste(ISOweek(date), ISOweekday(date), sep = "-"))) |
| 20 |
} |