sign
Signum Function

Description

Extracts the sign of each element in a vector and returns a vector of numeric values of the same length as the input.

Usage

sign(x)

Arguments

x an atomic object. Missing values (NA) are allowed.

Details

Missing values in the argument(s) create missing values in the result.
Value
For a numeric argument, returns 1, 0, and -1 corresponding to positive, zero, or negative values of the argument. For complex data, the result is equal to x/Mod(x) when x is not zero, and it is equal to 0+0i when it is zero.
sign is not defined for character data.
See Also
Comparison.
Examples
x <- c(-Inf, -3.14, 0, 3.14, Inf)
sign(x)
# [1] -1 -1  0  1  1

sign(x)*sqrt(abs(x)) # a signed square root

Package base version 6.1.4-13
Package Index