cut
applied to date-time objects.
"cut"(x, breaks, labels = NULL, start.on.monday = TRUE, right = FALSE, ...)
"cut"(x, breaks, labels = NULL, start.on.monday = TRUE, right = FALSE, ...)
"POSIXt"
or "Date"
.x
is to be cut into or an
interval specification, one of "sec"
, "min"
,
"hour"
, "day"
, "DSTday"
, "week"
,
"month"
, "quarter"
or "year"
, optionally
preceded by an integer and a space, or followed by "s"
.
For "Date"
objects only "day"
, "week"
,
"month"
, "quarter"
and "year"
are allowed.
right
). If
labels = FALSE
, simple integer codes are returned instead
of a factor.
breaks = "weeks"
, should the
week start on Mondays or Sundays?labels = FALSE
which returns
the integer level codes.
right = TRUE
and include.lowest = TRUE
will include both ends of the range of dates. Using breaks = "quarter"
will create intervals of 3 calendar
months, with the intervals beginning on January 1, April 1,
July 1 or October 1, based upon min(x)
as appropriate.
A vector breaks
will be sorted before use: labels
will
then correspond to the sorted vector.
seq.POSIXt
, seq.Date
, cut
## random dates in a 10-week period
cut(ISOdate(2001, 1, 1) + 70*86400*stats::runif(100), "weeks")
cut(as.Date("2001/1/1") + 70*stats::runif(100), "weeks")
# The standards all have midnight as the start of the day, but some
# people incorrectly interpret it at the end of the previous day ...
tm <- seq(as.POSIXct("2012-06-01 06:00"), by = "6 hours", length.out = 24)
aggregate(1:24, list(day = cut(tm, "days")), mean)
# and a version with midnight included in the previous day:
aggregate(1:24, list(day = cut(tm, "days", right = TRUE)), mean)
Run the code above in your browser using DataLab