epiweek_class | R Documentation |
Epiweeks are defined to start on a Sunday and span a 7 day period. Where they span calendar years, they are associated to the year which contains the majority of the week's days (i.e. the first epiweek a year is the one with at least four days in said year).
Internally, <grates_epiweek>
objects are stored as the number of weeks
(starting at 0) from the first Sunday after the Unix Epoch (1970-01-01).
That is, the number of seven day periods from 1970-01-04.
epiweek(year = integer(), week = integer())
as_epiweek(x, ...)
## Default S3 method:
as_epiweek(x, ...)
## S3 method for class 'Date'
as_epiweek(x, ...)
## S3 method for class 'POSIXt'
as_epiweek(x, ...)
## S3 method for class 'character'
as_epiweek(x, format, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"), ...)
## S3 method for class 'factor'
as_epiweek(x, format, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"), ...)
new_epiweek(x = integer())
is_epiweek(xx)
year |
Vector representing the year associated with
|
week |
Vector representing the week associated with 'year.
|
x , xx |
R objects. |
... |
Other values passed to as.Date(). |
format |
Passed to as.Date() unless If not specified, it will try tryFormats one by one on the first non-NA
element, and give an error if none works. Otherwise, the processing is via
|
tryFormats |
Format strings to try if format is not specified. |
epiweek()
is a constructor for <grates_epiweek>
objects. It takes a
vector of year and vector of week values as inputs. Length 1 inputs will be
recycled to the length of the other input and double
vectors will again be
converted to integer via as.integer(floor(x))
.
as_epiweek()
is a generic for conversion to <grates_epiweek>
.
Date, POSIXct, and POSIXlt are converted with the timezone respected.
Character objects are first coerced to date via as.Date()
unless
format = "yearweek"
in which case input is assumed to be in the form
"YYYY-Wxx" and parsed accordingly.
new_epiweek()
is a minimal constructor for <grates_epiweek>
objects
aimed at developers. It takes, as input, the number of epiweeks since the
sunday after the Unix Epoch that you wish to represent. double
vectors will
be converted to integer via as.integer(floor(x))
.
A <grates_epiweek>
object.
The yearweek and isoweek classes.
# date coercion
as_epiweek(Sys.Date())
# POSIXt coercion
as_epiweek(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"))
# character coercion assumes date input by default
as_epiweek("2019-05-03")
# character coercion can handle YYYY-Www format too
as_epiweek("2019-W12", format = "yearweek")
# construction
epiweek(year = 2000, week = 3)
# direct construction
stopifnot(
identical(
new_epiweek(0:1),
as_epiweek("1970-01-04") + 0:1
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.