zero_lomf: Last [non-zero] Observation Moved Forward (lomf)

Description Usage Arguments Value Examples

View source: R/IRmapping_functions.R

Description

Finds the index, for each row, of the previous row with a non-zero value

Usage

1
zero_lomf(x, first = TRUE)

Arguments

x

Numeric vector.

first

(logical) Whether to consider first value as a non-zero value whose index is moved forward even if it is zero. This prevents having NAs in the results and somewhat assumes that, for a time series, the day prior to the first value is non-zero.

Value

Numeric vector of the indices of the previous non-zero for each element of the input vector.

Examples

1
2
3
4
5
test1 <- c(1,1,1,0,0,0,0,1,1)
zero_lomf(test1)
test2 <- c(0,0,0,0,0,1,1,0,1)
zero_lomf(test2, first=FALSE)
zero_lomf(test2, first=TRUE)

NaiaraLopezRojo/globalIRmap documentation built on Dec. 17, 2021, 5:19 a.m.