trimmer: Trim a series by some percentage

View source: R/utilities.R

trimmerR Documentation

Trim a series by some percentage

Description

Trim a series by some percentage

Usage

trimmer(x, prc = 0.1)

Arguments

x

series to trim

prc

the percentage of data to trim from either side of x; this cannot be less than 0 or greater than 0.5.

Details

The trimming is done with sort.int, which may be problematic for timeseries. The best option is to trim an index series and use that to re-sample the timeseries. See Examples.

Also sets an attribute 'trim' with details of the trimming.

Examples

# default is a 10% trim
trimmer(1:10)  # 2 3 4 5 6 7 8 9

# but sort is used...
set.seed(1234)
x <- round(runif(10, max = 10)) # note order of values
trimmer(x) # trimmed, but sorted

# we can fix this by trimming an index:
x[trimmer(seq_along(x))] # trimmed, with order retained


abarbour/pborepo documentation built on April 27, 2022, 8:47 a.m.