datetime2fac: Transform a date-time vector to a factor

Description Usage Arguments Details Value Note See Also Examples

View source: R/datetime2fac.R

Description

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

Usage

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

Arguments

p

date-time vector

rng

range of the factor.

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.

Value

A factor vector.

Note

This function is still in development stage, and can be improved and optimized. ff vectors are not implemented yet

See Also

num2fac

Examples

1
2
3
4
5
6
7
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)

mtennekes/tabplot documentation built on March 8, 2021, 6:11 p.m.