ts_pad_contig: Apply 'stats::na.contiguous()' and pad result to original...

Description Usage Arguments Details Value Examples

View source: R/ts_pad_contig.R

Description

Apply stats::na.contiguous() to a timeseries x and pad the result back to its original length with NAs. Designed for use in data.table[, j = pad_contiguous(x), by = g], where the replacement needs to have the same length as the original.

Usage

1

Arguments

x

Either a numeric vector, or stats::ts() object.

Details

Preserves start and frequency of x, if it is a stats::ts() object.

Value

An object of class(x) and length(x) with NAs, except for the longest contiguous stretch in x

Examples

1
2
3
4
x <- c(NA, 1, NA, NA, 1:5, NA)
ts_pad_contig(x)
x <- ts(x, start = c(2000, 1), frequency = 12)
ts_pad_contig(x)

thorepet/thoremisc documentation built on Oct. 8, 2021, 7:48 a.m.