Skip to contents

Adds missing values to turn an irregular time series into a regular one. This function is currently experimental. Only works or target frequencies 1,2,4,12.

Usage

regularize(x)

Arguments

x

an irregular time series object of class zoo or xts.

Examples

ts1 <- rnorm(5)
dv <- c(
  seq(as.Date("2010-01-01"), length = 3, by = "3 years"),
  seq(as.Date("2018-01-01"), length = 2, by = "2 years")
)
library(zoo)
xx <- zoo(ts1, dv)
regularize(xx)
#> Time Series:
#> Start = 2010 
#> End = 2020 
#> Frequency = 1 
#>  [1]  1.6700886         NA         NA -1.6875603         NA         NA
#>  [7]  0.4565716         NA  0.2188939         NA  2.4533042

dv2 <- c(seq(as.Date("2010-01-01"), length = 20, by = "1 months"))
dv2 <- dv2[c(1:10, 14:20)]
xx2 <- zoo(rnorm(length(dv2)), dv2)
regularize(xx2)
#>             Jan        Feb        Mar        Apr        May        Jun
#> 2010 -0.9580244  1.3530311  1.2738529  0.1868429  0.2705550  0.3431659
#> 2011         NA -0.7662984 -0.4223377 -1.7581646  0.7256151 -1.9287957
#>             Jul        Aug        Sep        Oct        Nov        Dec
#> 2010 -1.6331552 -0.5648019 -2.0137132 -0.8579509         NA         NA
#> 2011  0.8934381  0.2672875