chron (version 2.1-7)

cut.dates: Create a Factor from a chron or dates object

Usage

cut.dates(x, breaks, labels, start.on.monday = T)

Arguments

x
chron or dates object (see chron), character dates such as "10/04/91" or Julian dates).
breaks
either a vector of break points (a dates vector, character dates such as "10/04/91" or Julian dates), a constant specifying number of equally spaced intervals extending from min(x)-1 to max(x)+1, or one o
labels
character labels for intervals.
start.on.monday
should weeks be assumed to start on Mondays? Default is TRUE. Set to FALSE if weeks start on Sundays; for other days of the week specify the corresponding number: Sunday == 0, Monday == 1, Tuesday == 2, ...

Value

  • an ordered factor whose levels represent the various time intervals.

See Also

seq.dates

Examples

Run this code
# days from 07/01/92 thru 07/15/92 fell into 3 Monday-started weeks
cut(dates("07/01/92") + 0:14, "weeks")
# [1] week 1 week 1 week 1 week 1 week 1 week 2 week 2 week 2 
# [9] week 2 week 2 week 2 week 2 week 3 week 3 week 3

dts <- dates(c("02/27/92", "02/27/92", "01/14/92",
               "02/28/92", "02/01/92"))
cut(dts, "months")
# [1] Feb 92 Feb 92 Jan 92 Feb 92 Feb 92
boxplot(runif(5) ~ cut(dts, "months"))

Run the code above in your browser using DataCamp Workspace