This is an auxiliary function that makes all values in numeric vector x strictly
positive by replacing all values equal to or lower than zero with
the values in small.pos
. small_pos
stands for 'small positive constant'.
Arguments
- x
A numeric vector.
- small_pos
A (small) positive number to replace negative values and 0s.
Examples
(x <- rnorm(30))
#> [1] -0.56806622 -0.02322376 1.01634829 -0.99054622 -1.48586320 -0.40771472
#> [7] 2.93666146 1.54579687 0.42082621 1.58568472 0.48125230 -0.46277531
#> [13] 1.51943818 0.08263309 0.87203974 -0.73417900 -0.67657782 -1.59305553
#> [19] -0.49254365 0.97809285 0.46618102 1.07503671 -2.23482154 1.70054924
#> [25] -0.12645249 1.88912930 -0.53645833 0.65917628 -0.97682721 -0.85729275
zero_plus(x)
#> [1] 0.00001000 0.00001000 1.01634829 0.00001000 0.00001000 0.00001000
#> [7] 2.93666146 1.54579687 0.42082621 1.58568472 0.48125230 0.00001000
#> [13] 1.51943818 0.08263309 0.87203974 0.00001000 0.00001000 0.00001000
#> [19] 0.00001000 0.97809285 0.46618102 1.07503671 0.00001000 1.70054924
#> [25] 0.00001000 1.88912930 0.00001000 0.65917628 0.00001000 0.00001000