Learn R Programming

ggdistribute (version 1.0.3)

trim_ends: Trim extreme values at each end of a vector.

Description

Trim extreme values at each end of a vector.

Usage

trim_ends(x, trim = 0.05, na.rm = TRUE)

Arguments

x

A numeric vector

trim

Proportion of vector length to trim. Must be between 0 and 1. E.g., a value 0.05 (default) trims 2.5% off each end of a sorted vector.

na.rm

omit NA values. May result in different size vector.

Value

A numeric vector in the original order of x, but with trimmed values as NA if na.rm=TRUE or with these values removed if FALSE (which will result in a different sized vector from the input).

Examples

Run this code
# NOT RUN {
x <- rgamma(10000, 1, 1)
range(x)
length(x)     # <- 10000
sum(is.na(x)) # <- 0

t <- trim_ends(x, trim = 0.1)
range(t)
length(t)     # <- 9000
sum(is.na(t)) # <- 0

t <- trim_ends(x, 0.1, na.rm = FALSE)
range(t, na.rm = TRUE)
length(t)     # <- 10000
sum(is.na(t)) # <- 1000
# }

Run the code above in your browser using DataLab