cut.POSIXt {base}R Documentation

Convert a Date or Date-Time Object to a Factor

Description

Method for cut applied to date-time objects.

Usage

## S3 method for class 'POSIXt':
cut(x, breaks, labels = NULL, start.on.monday = TRUE,
    right = FALSE, ...)

## S3 method for class 'Date':
cut(x, breaks, labels = NULL, start.on.monday = TRUE,
    right = FALSE, ...)

Arguments

x an object inheriting from class "POSIXt" or "Date".
breaks a vector of cut points or number giving the number of intervals which x is to be cut into or an interval specification, one of "sec", "min", "hour", "day", "DSTday", "week", "month" or "year", optionally preceded by an integer and a space, or followed by "s". For "Date" objects only "day", "week", "month" and "year" are allowed.
labels labels for the levels of the resulting category. By default, labels are constructed from the left-hand end of the intervals (which are include for the default value of right). If labels = FALSE, simple integer codes are returned instead of a factor.
start.on.monday logical. If breaks = "weeks", should the week start on Mondays or Sundays?
right, ... arguments to be passed to or from other methods.

Details

Using both right = TRUE and include.lowest = TRUE will include both ends of the range of dates.

Value

A factor is returned, unless labels = FALSE which returns the integer level codes.

See Also

seq.POSIXt, seq.Date, cut

Examples

## random dates in a 10-week period
cut(ISOdate(2001, 1, 1) + 70*86400*runif(100), "weeks")
cut(as.Date("2001/1/1") + 70*runif(100), "weeks")

[Package base version 2.2.1 Index]