##
## 1. default
##
sx <- sign((-2):2)
# check
stopifnot(
all.equal(sx, base::sign((-2):2))
)
##
## 2. with zero = 1
##
s1 <- sign((-2):2, 1)
# check
stopifnot(
all.equal(s1, rep(c(-1, 1), c(2,3)))
)
Run the code above in your browser using DataLab