isoweek {FluMoDL} | R Documentation |
Calculate the ISO week & year for a Date
Description
This function takes a vector of Date objects and calculates the week and year according to ISO 8601. It is flexible in its output.
Usage
isoweek(x, type = "both_num", sep = "-", inv = FALSE,
colnames = c("isoyear", "isoweek"))
Arguments
x |
A vector of class |
type |
A string (one of "week", "year", "both_text", "both_num" or "matrix") that determines the kind of output the function returns. See "Return value". |
sep |
Seperator between year and week, applicable if |
inv |
If |
colnames |
Names for the matrix columns if |
Details
This function calculates the week number according to ISO 8601. Note that dates near the start or end of a given year may belong to the previous or next year respectively, thus the year needs to be calculated too.
Value
Different according to the function's type
argument. If
"both_num"
(the default), a vector of 6-digit integers is returned, in a
YYYYWW format. If "week"
or "year"
, only the week number or year is
returned, respectively. If "both_text"
, then a character vector of the same
length as x
is returned, containing both the year and week number, seperated
by sep
, and inverted if inv=TRUE
. Finally, if type="matix"
, both
year and week numbers are returned in a two-column matrix, with the columns named as
in colnames
.
Examples
isoweek(Sys.Date())
isoweek("1980-8-19", "both_text", sep="/", inv=TRUE)
isoweek(c("2004-5-31", "2006-6-10", "2007-8-20"), "matrix")