trimmedMean: Trimmed Mean

View source: R/trimmedMean.R

trimmedMeanR Documentation

Trimmed Mean

Description

This function allows more flexible options for calculating a trimmed mean compared to mean (from the base-package).

Usage

trimmedMean(
  dat,
  trim = c(l = 0.2, u = 0.2),
  silent = FALSE,
  debug = FALSE,
  callFrom = NULL
)

Arguments

dat

(numeric) numeric vector

trim

(numeric, length=2) specifies how data should get trimmed, lower and upper fraction(s) to exclude have to be assigned separately. The lower and upper fraction may be named 'l' and 'u'. The value 0 means that all (sorted) data on a given side will be used.

silent

(logical) suppress messages

debug

(logical) additional messages for debugging

callFrom

(character) allows easier tracking of messages produced

Details

If the second value of trim is <0.5 it is supposed that this indicates a fraction from the upper end the vector-dat as mean does. Otherwise, trim=c(l=0.2,u=0.7) will be interpreted indication to use the 20th percentile to 70th percentile of dat.

Please note, that trimmed means - and in particular asymmetric trimmed means - should be used with caution as there is also a risk of introducing bias.

Value

This function returns a (numeric) vector with the trimmed mean

See Also

mean (symmetric trimming only)

Examples

x <- c(17:11,27:28)
mean(x); mean(x, trim=0.15)
trimmedMean(x, trim=c(l=0, u=0.7))   # asymmetric trim


wrMisc documentation built on Sept. 11, 2024, 6:10 p.m.