Learn R Programming

alR (version 2.2.0)

trim: (Trimmed) vector.

Description

Find a vector excluding trimmed values, on which the calculation of a statistic will result in a trimmed statistic.

Usage

trim(x, trim = 0, na.rm = FALSE, ...)

Arguments

x

A numeric vector of real values.

trim

The fraction (0 to 0.5) of observations to be trimmed from each end of x.

na.rm

A logical value indicating whether NA values should be stripped.

...

Further arguments passed to or from other methods.

Value

If trim is zero (the default), the values in x is returned. If x is not logical (coerced to numeric), numeric (including integer) or complex, NA_real_ is returned, with a warning. If trim is non-zero, a symmetrically trimmed vector is returned with a fraction of trim observations deleted from each end.

Examples

Run this code
# NOT RUN {
x <- c(rnorm(100), 100)
mean(x)
mean(x, trim=0.01)
mean(trim(x, trim=0.01))
sd(x)
sd(trim(x, trim=0.01))

# }

Run the code above in your browser using DataLab