R/as.Date.ts.R

Defines functions as.Date.ts

Documented in as.Date.ts

# as.Date.numeric <- function (x, origin = "1970-01-01", ...) 
#  as.Date(origin, ...) + x

as.Date.ts <- function(x, offset = 0, ...) {
   time.x <- unclass(time(x)) + offset
   if (frequency(x) == 1)
	as.Date(paste(time.x, 1, 1, sep = "-"))
   else if (frequency(x) == 4)
	as.Date(paste((time.x + .001) %/% 1, 3*(cycle(x)-1)+1, 1, sep = "-"))
   else if (frequency(x) == 12)
	as.Date(paste((time.x + .001) %/% 1, cycle(x), 1, sep = "-"))
   else
	stop("unable to convert ts time to Date class")
}

Try the zoo package in your browser

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

zoo documentation built on June 8, 2023, 6:59 a.m.