Trim a vector so that all values are greater than 0 and less than 1.
Arguments
- x
A numeric vector. Can be an rvec.
Details
If
min
is lowest element ofx
that is higher than 0, andmax
is the highest element ofx
that is lower than 1, thentrim_01()
shifts all elements of
x
that are lower thanmin
upwards, so that they equalmin
, andshifts all elements of
x
that are higher thanmax
downwards, so that they equalmax
.
See also
logit()
,invlogit()
Logit transformation
Examples
x <- c(1, 0.98, -0.001, 0.5, 0.01)
trim_01(x)
#> [1] 0.98 0.98 0.01 0.50 0.01