Learn R Programming

cwhmisc (version 4.0)

signp: Sign Function

Description

sign returns a vector with the signs of the corresponding elements of x: ifelse(x >= 0, 1, -1) .

Note that sign does not operate on complex vectors.

Usage

signp(x)

Arguments

x
a numeric vector

See Also

sign

Examples

Run this code
signp(-2:3)# -1 -1 1 1 1 1
(m <- matrix(rnorm(9),3,3))
m %*% diag(signp(diag(m)))

Run the code above in your browser using DataLab