| 1 |
#' Day of week according to ISO 8601 |
| 2 |
#' |
| 3 |
#' This function returns the weekday of a given date according to ISO 8601. |
| 4 |
#' It is an substitute for the "\code{\%u}" format which is not implemented on Windows. |
| 5 |
#' |
| 6 |
#' @param date Vector which can be coerced to class \code{Date} |
| 7 |
#' @return An integer vector of weekdays (1-7, Monday is 1) |
| 8 |
#' @author Uwe Block \email{u.block.mz@@googlemail.com} |
| 9 |
#' @seealso \code{\link{strptime}} |
| 10 |
#' @export |
| 11 |
#' @examples |
| 12 |
#' x <- paste(1999:2011, "-12-31", sep = "") |
| 13 |
#' y <- as.Date(x) |
| 14 |
#' data.frame(date = format(y), weekday = ISOweekday(y)) |
| 15 |
#' data.frame(date = x, weekday = ISOweekday(x)) |
| 16 |
ISOweekday <- function(date) { |
| 17 |
date <- as.Date(date) |
| 18 |
return(as.integer((as.integer(format(date, "%w"))+6) %% 7 + 1)) |
| 19 |
} |
| 20 |
|