sign(e1) compare(e1, e2)
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.
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.
sign(x)*sqrt(abs(x)) # a signed square rootcompare(5:1,1:5) # returns c(1, 1, 0, -1, -1)
compare("MORGAN", "MYER") # which is first alphabetically?