Learn R Programming

rkeops (version 2.2.2)

sign.default: Sign function

Description

sign returns a vector with the signs of the corresponding elements of x (the sign of a real number is 1, 0, or \(-1\) if the number is positive, zero, or negative, respectively).

Note that sign does not operate on complex vectors.

Usage

# S3 method for default
sign(x)

Arguments

x

a numeric vector

Author

R core team and contributors

Details

This is an internal generic primitive function: methods can be defined for it directly or via the Math group generic.

See Also

Examples

Run this code
sign(pi)    # == 1
sign(-2:3)  # -1 -1 0 1 1 1

Run the code above in your browser using DataLab