trimmedMean | R Documentation |
This function allows more flexible options for calculating a trimmed mean compared to mean
(from the base-package).
trimmedMean(
dat,
trim = c(l = 0.2, u = 0.2),
silent = FALSE,
debug = FALSE,
callFrom = NULL
)
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 |
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.
This function returns a (numeric) vector with the trimmed mean
mean
(symmetric trimming only)
x <- c(17:11,27:28)
mean(x); mean(x, trim=0.15)
trimmedMean(x, trim=c(l=0, u=0.7)) # asymmetric trim
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.