Learn R Programming

tabplot (version 1.3-3)

datetime2fac: Transform a date-time vector to a factor

Description

Transform a date-time vector from class POSIXt or Date to a factor.

Usage

datetime2fac(p, rng = range(p, na.rm = TRUE))

Arguments

p

date-time vector

rng

range of the factor.

Value

A factor vector.

Details

The range rng is cut according to different pretty rounded time periods. The cut with the number of levels that is closest to 6 is chosen. Vector p is cut accordingly. Values of p outside rng are translated to NA.

See Also

num2fac

Examples

Run this code
# NOT RUN {
d <- as.Date("2012-12-21") + sample.int(500, 1000, replace=TRUE)
d2 <- datetime2fac(d)
levels(d2)

t <- as.POSIXlt(Sys.time(), "GMT") + sample.int(1e5, 1000, replace=TRUE)
t2 <- datetime2fac(t)
levels(t2)
# }

Run the code above in your browser using DataLab