Learn R Programming

runner (version 0.2.1)

whichd_run: Index of previous, different element

Description

Index of previous element different than current

Usage

whichd_run(x, k = 0L, na_pad = FALSE)

Arguments

x

vector of any type where running index is calculated

k

running window size. By default window size equals length(x). Allow varying window size specified by vector of length(x)

na_pad

logical (default na_pad=FALSE) - if TRUE first k-results will be filled by NA. If k is not specified na_pad=F by default.

Value

numeric vector of length equals length of x containing running index length in k-long window.

Examples

Run this code
# NOT RUN {
set.seed(11)
x1 <- sample(c("a","b"),15,replace=TRUE)
x2 <- sample(c(NA_character_,"a","b"),15,replace=TRUE)
k  <- sample(1:4,15,replace=TRUE)
whichd_run(x1)
whichd_run(x1, k=2)
whichd_run(x2, na_pad=TRUE, k=3)
whichd_run(x1, k=k)
# }

Run the code above in your browser using DataLab