Signum Function and Comparison

DESCRIPTION:
Returns a vector of numeric values indicating the elementwise comparison of two vectors (compare) or the comparison of a vector with zero (sign).

USAGE:
sign(e1)
compare(e1, e2)

REQUIRED ARGUMENTS:
e1, e2:
atomic object.
Missing values (NA) are allowed.

VALUE:
sign returns +1, 0, and -1 corresponding to positive, zero, or negative values of its argument when this is numeric. For complex data the result is equal to x/Mod(x) when x is not zero and equals 0+0i when it is zero. sign is not defined for character data.

compare always returns a numeric object, containing values greater than, equal to, or less than 0 corresponding to elements where e1 is respectively greater than, equal to, or less than e2. It behaves like the S-PLUS arithmetic and comparison operators in that it replicates shorter arguments and preserves attributes if one of the arguments has them.


DETAILS:
Missing values in the argument(s) create missing values in the result.

Comparisons of complex values are done first on the real part with the imaginary part used to break ties in the real part. Character data are compared in terms of the ASCII codes so digits are less than capital letters, which are less than small letters.

The value of sign(x) is identical to compare(x,0) for noncomplex numeric data.


SEE ALSO:
Comparison .

EXAMPLES:
sign(x)*sqrt(abs(x)) # a signed square root

compare(5:1,1:5) # returns c(1, 1, 0, -1, -1)

compare("MORGAN", "MYER") # which is first alphabetically?