# sign

0th

Percentile

##### Sign Function

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.

Keywords
arith
##### Usage
sign(x)
x
a numeric vector
##### Details

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

abs

• sign
##### Examples
library(base) sign(pi) # == 1 sign(-2:3) # -1 -1 0 1 1 1 
Documentation reproduced from package base, version 3.3, License: Part of R @VERSION@

### Community examples

richie@datacamp.com at Jan 17, 2017 base v3.3.2

Positive numbers return 1; negative numbers return -1, zero returns zero. Missing values and NaN are still missing and NaN respectively. {r} x <- c( -Inf, -pi, -2, -1, -.Machine$double.xmin, 0, .Machine$double.xmin, 1, 2, pi, Inf, NA, NaN ) data.frame(x = x, sign_x = sign(x))