keeponly function

Eliminate Consecutive Extreme Values

Eliminate Consecutive Extreme Values

Generate the index for eliminating values beyond a given maximum number of consecutive extremes allowed.

keeponly(x, extremes = c(0, 100), nconsec = 2)

Arguments

  • x: A numeric vector, with no missing values.
  • extremes: A numeric vector of length two giving the boundary limits for x, default c(0, 100).
  • nconsec: An integer scalar, the maximum number of consecutive extreme values allowed, default 2.

Returns

A logical vector for selecting all elements of x without exceeding nconsec consecutive extreme values.

Examples

vec <- c(0, 0, 0, 4, 4, 4, 100, 100, 100, 100) vec[keeponly(vec)] # the original vector need not be ordered vec <- c(100, 4, 100, 4, 0, 100, 0, 4, 0, 100) keeponly(vec)
  • Maintainer: Jean V. Adams
  • License: GPL
  • Last published: 2017-03-20