Learn R Programming

cwhmisc (version 6.0)

signp: Sign Function

Description

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

Usage

signp(x)

Arguments

x
a numeric vector

See Also

sign

Examples

Run this code
signp(-1:1) # -1 1 1 instead of sign(-1:1) = -1 0 1
(m <- matrix(rnorm(9),3,3))
m %*% diag(signp(diag(m))) 

Run the code above in your browser using DataLab