Skip to contents

Cut a numeric vector between min and max. Values lower than min or higher than max are substituted with the provided values.

Usage

trim(x, min = NULL, max = NULL)

Arguments

x

the numeric vector

min

the minimum value. Default to `NULL`. If `NULL`, the lower bound is not modified.

max

the maximum value. Default to `NULL`. If `NULL`, the upper bound is not modified.

Examples

x <- runif(20, 0, 20)
trim(x, min = 5, max = 10)
#>  [1]  8.655763 10.000000 10.000000  8.714363 10.000000 10.000000  5.000000
#>  [8] 10.000000  5.000000 10.000000 10.000000  5.000000 10.000000 10.000000
#> [15]  8.147227 10.000000 10.000000  7.083735  9.116803  5.000000
trim(x, max = 10)
#>  [1]  8.655763 10.000000 10.000000  8.714363 10.000000 10.000000  2.562315
#>  [8] 10.000000  2.580325 10.000000 10.000000  4.835522 10.000000 10.000000
#> [15]  8.147227 10.000000 10.000000  7.083735  9.116803  4.400494
trim(x, min = 5)
#>  [1]  8.655763 18.405516 12.320289  8.714363 17.946088 15.380270  5.000000
#>  [8] 10.772662  5.000000 10.219298 10.875854  5.000000 16.062882 18.958274
#> [15]  8.147227 10.294891 19.630837  7.083735  9.116803  5.000000