Classify the sign of the elements of a vector

signum(x, epsilon = 1e-05)

Arguments

x

vector of values to test

epsilon

magnitude threshold

Value

Returns a vector with elements +1,0 or -1.

Details

Calculates the sign of the elements of then vector x, except that values less than epsilon in magnitude are rounded down to zero.

Examples

signum(c(-40,-3,-0.1E-8,0,2,5))
#> [1] -1 -1 0 0 1 1