keeponly {LW1949}R Documentation

Eliminate Consecutive Extreme Values

Description

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

Usage

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.

Value

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)

[Package LW1949 version 1.1.0 Index]