ts_regular: Enforce Regularity

Description Usage Arguments Examples

View source: R/ts_regular.R

Description

Enforces regularity in data frame and xts objects, by turning implicit NAs into explicit NAs. In ts objects, regularity is automatically enforced.

Usage

1
ts_regular(x, fill = NA)

Arguments

x

ts-boxable time series, an object of class ts, xts, zoo, data.frame, data.table, tbl, tbl_ts, tbl_time, tis, irts or timeSeries.

fill

instead of NA, an alternative value can be specified

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
x0 <- AirPassengers
x0[c(10, 15)] <- NA
x <- ts_na_omit(ts_dts(x0))
ts_regular(x)
ts_regular(x, fill = 0)

m <- mdeaths
m[c(10, 69)] <- NA
f <- fdeaths
f[c(1, 3, 15)] <- NA

ts_regular(ts_na_omit(ts_dts(ts_c(f, m))))

Example output

           time value
  1: 1949-01-01   112
  2: 1949-02-01   118
  3: 1949-03-01   132
  4: 1949-04-01   129
  5: 1949-05-01   121
 ---                 
140: 1960-08-01   606
141: 1960-09-01   508
142: 1960-10-01   461
143: 1960-11-01   390
144: 1960-12-01   432
           time value
  1: 1949-01-01   112
  2: 1949-02-01   118
  3: 1949-03-01   132
  4: 1949-04-01   129
  5: 1949-05-01   121
 ---                 
140: 1960-08-01   606
141: 1960-09-01   508
142: 1960-10-01   461
143: 1960-11-01   390
144: 1960-12-01   432
     id       time value
  1:  f 1974-02-01   689
  2:  f 1974-03-01    NA
  3:  f 1974-04-01   677
  4:  f 1974-05-01   522
  5:  f 1974-06-01   406
 ---                    
139:  m 1979-08-01   975
140:  m 1979-09-01    NA
141:  m 1979-10-01  1081
142:  m 1979-11-01  1294
143:  m 1979-12-01  1341

tsbox documentation built on April 30, 2020, 1:05 a.m.