posixt-group | R Documentation |
This is a POSIXct/POSIXlt method for the date_group()
generic.
date_group()
groups by a single component of a date-time, such as month
of the year, day of the month, or hour of the day.
If you need to group by more complex components, like ISO weeks, or quarters, convert to a calendar type that contains the component you are interested in grouping by.
## S3 method for class 'POSIXt'
date_group(
x,
precision,
...,
n = 1L,
invalid = NULL,
nonexistent = NULL,
ambiguous = x
)
x |
A date-time vector. |
precision |
One of:
|
... |
These dots are for future extensions and must be empty. |
n |
A single positive integer specifying a multiple of |
invalid |
One of the following invalid date resolution strategies:
Using either If If |
nonexistent |
One of the following nonexistent time resolution strategies, allowed to be either length 1, or the same length as the input:
Using either If If |
ambiguous |
One of the following ambiguous time resolution strategies, allowed to be either length 1, or the same length as the input:
Alternatively, Finally, If If |
x
, grouped at precision
.
x <- as.POSIXct("2019-01-01", "America/New_York")
x <- add_days(x, -3:5)
# Group by 2 days of the current month.
# Note that this resets at the beginning of the month, creating day groups
# of [29, 30] [31] [01, 02] [03, 04].
date_group(x, "day", n = 2)
# Group by month
date_group(x, "month")
# Group by hour of the day
y <- as.POSIXct("2019-12-30", "America/New_York")
y <- add_hours(y, 0:12)
y
date_group(y, "hour", n = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.