na_prev: Replace missing value with previous non-missing value

Description Usage Arguments Examples

View source: R/RcppExports.R

Description

Replace missing value with previous non-missing value

Usage

1
na_prev(x, lag = 1L)

Arguments

x

a vector.

lag

replace x[i] missing value with the x[i-lag] value.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
na_prev( c(NA, 1, 2, NA, 3, NA, NA) )
na_prev( c(NA, 1.001, 2.5, NA, 3.0004, NA, NA) )
na_prev( c("a", NA, "b", NA, "c") )
na_prev( c(TRUE, NA, FALSE, NA, TRUE) )

set.seed(1234)
x <- rep(1:7, 3)
x[sample(7*3, 5)] <- NA
x
na_prev(x, 7)

twolodzko/misster documentation built on May 24, 2019, 2:54 p.m.