Learn R Programming

runner (version 0.2.1)

min_run: Running minimum

Description

min_run calculates running min on given x numeric vector, specified k window size.

Usage

min_run(x, k = 0L, na_rm = TRUE, na_pad = FALSE, idx = 0L)

Arguments

x

input numeric vector where running minimum is calculated.

k

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

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.

idx

an optional integer vector containing idx numbers of observation.

Value

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

Examples

Run this code
# NOT RUN {
set.seed(11)
x1 <- sample( c(1,2,3), 15, replace=TRUE)
x2 <- sample( c(NA,1,2,3), 15, replace=TRUE)
k  <- sample( 1:4, 15, replace=TRUE)
min_run(x1) # simple cumulative minimum
min_run(x2, na_rm = TRUE) # cumulative minimum with removing NA.
min_run(x2, na_rm = TRUE, k=4) # minimum in 4-element window
min_run(x2, na_rm = FALSE, k=k) # minimum in varying k window size
# }

Run the code above in your browser using DataLab