Description Usage Arguments Details Note Author(s) Examples
Converts a vector of dates to weeks using data.table's IDate.
1 | round_weeks(x)
|
x |
Vector of dates |
This function uses Sunday as the first day of the week, and will round the
vector of dates to the first day of the week. For other units of time
(e.g. month, year) data.table:::round.IDate
is suggested. Currently
IDate's round function for 'weeks' will split any week overlapping two
years into two week parts, which usually starts the rounded weeks in the
second year on a new day. This function is a workaround for that behavior.
More details about week rounding issue (mentioned in details) here: https://github.com/Rdatatable/data.table/issues/747
Depends on data.table
Gene Leynes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | require(data.table)
require(geneorama)
## Create a sequence of dates (or IDates)
dd <- seq(as.IDate("2013-12-22"), as.IDate("2014-01-18"), 1)
## Weeks rounded using default data.table method:
round(dd, 'weeks')
## Weeks rounded using "round_weeks":
round_weeks(dd)
## Rounding methods shown side-by-side
data.table(date_original = dd,
weeks_dt = round(dd, 'weeks'),
weeks_new = round_weeks(dd),
wday = wday(dd),
weekday = weekdays(dd))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.