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

Description Usage Arguments Value Examples

Description

Trim extreme values at each end of a vector.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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

iamamutt/ggdistribute documentation built on May 8, 2019, 3:12 a.m.