Learn R Programming

runner (version 0.1.0)

whichmin_run: Running which.min

Description

Running index of the (first or last) maximum.

Usage

whichmin_run(x, k = 0L, which = "last", na_rm = TRUE,
  na_pad = FALSE)

Arguments

x

input logical vector where running whichrun is calculated.

k

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

which

specifies whether "first" or "last" index is returned.

na_rm

logical (default na_rm=TRUE) - if TRUE NA are replaced by last observed minimum prior to element.

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 of maximum in k-long window.

Examples

Run this code
# NOT RUN {
set.seed(11)
x1 <- c(1, 1, 2, 1, 1, 3, 1, 1, 3, 1, 1, 2, 3, 3, 3)
x2 <- c(2, 1, 1, NA, 3, 2, 1, NA, 1, NA, NA, NA, 1, 2, 1)
k  <- c(5, 1, 8, 1, 1, 15, 2, 5, 14, 2, 3, 7, 14, 13, 12)
whichmin_run( x1 , which="first") # running index of minimum
whichmin_run(x1, which="last")
whichmin_run( x2, na_rm = TRUE , which="last" ) # running min-index ommiting NA
whichmin_run(x2 , k=3, na_rm = TRUE, which="first") # running min-index in 3-element window
whichmin_run( x2 , k = k , na_rm = TRUE, which = "last") # running min-index in varying window size
# }

Run the code above in your browser using DataLab