Learn R Programming

runner (version 0.1.0)

whichmax_run: Running which.max

Description

Running index of the (first or last) maximum.

Usage

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

Arguments

x

numeric (or integer) vector for which 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 {
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)
whichmax_run(x1, which="first")
whichmax_run(x2, na_rm = TRUE, which="last")
whichmax_run(x2, k=3, na_rm = TRUE, which="last")
whichmax_run(x2 , k=k, na_rm = FALSE, which="first")
# }

Run the code above in your browser using DataLab