R/misc.R

Defines functions years emptyDate is.wholenumber

years <- function(x) {
    # Optimize to only convert unique values in x
    y <- unique(x)
    if (length(x) > 10) {
        y <- unique(x)
        if (length(y) >= length(x))
            y <- NULL
    }
    if (!is.null(y)) {
        i <- match(x, y)
        return(as.POSIXlt(y)$year[i] + 1900)
    } else {
        return(as.POSIXlt(x)$year + 1900)
    }
}

emptyDate <- function() .dateParse.origin[0]

is.wholenumber <- function(x) any(floor(x) == x)

Try the TimeWarp package in your browser

Any scripts or data that you put into this service are public.

TimeWarp documentation built on May 2, 2019, 4:48 p.m.