The sign() function used to get sign of numeric value or numeric vector in R. It returns -1 for negative numbers, 0 for zero and 1 for positive number.

The following method shows how you can do it with syntax.

Method 1: Use sign() Function


x: Number ot numeric vector

The follwing example shows how to use sign() function.

Use sign() Function on Numeric Vector

Let’s apply sign() function on numeric value:

# Define vector
num1 <- c(15,-19,18,-23,27,44,-59)

# Get sign of element


[1]  1 -1  1 -1  1  1 -1

As we can see in the output -19,-23 and -59 have sign -1 because they’re negative, 15,18,27 and 44 have sign 1 because they are positive.