DescTools (version 0.99.15)

Trim: Trim a Vector

Description

Clean data by means of trimming, i.e., by omitting outlying observations.

Usage

Trim(x, trim = 0.1, na.rm = FALSE)

Arguments

x
a numeric vector to be trimmed.
trim
the fraction (0 to 0.5) of observations to be trimmed from each end of x before the mean is computed. Values of trim outside that range are taken as the nearest endpoint. The argument can also be set to an integer value. If trim is set to >1
na.rm
a logical value indicating whether NA values should be stripped before the computation proceeds.

Value

  • The trimmed vector x. The result vector will be sorted (as sort.int is used within the function).

Details

A symmetrically trimmed vector x with a fraction of trim observations (resp. the given number) deleted from each end will be returned. If trim is set to a value >0.5 or to an integer value > n/2 then the result will be NA.

See Also

Winsorize

Examples

Run this code
## generate data
set.seed(1234)     # for reproducibility
x <- rnorm(10)     # standard normal
x[1] <- x[1] * 10  # introduce outlier

## Trim data
x
Trim(x, trim=0.1)

## Trim fixed number, say cut the 3 extreme elements from each end
Trim(x, trim=3)

Run the code above in your browser using DataCamp Workspace