[R] are arithmetic comparison operators binary?

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon Feb 23 12:06:32 CET 2009


the man page for relational operators (see, e.g., ?'<') says:

"
Binary operators which allow the comparison of values in atomic vectors.

Arguments:

    x, y: atomic vectors, symbols, calls, or other objects for which
          methods have been written.
"

it is somewhat surprizing that the following works:

    '<'(1)
    # logical(0)

    '<'()
    # logical(0)

    '<'(1,2,3)
    # TRUE

what does 'binary' mean here, precisely?  in the first two examples, one
might suspect that '<' treats the missing arguments as missing values,
but this would not be coherent with what the man page says:

"
 Missing values ('NA') and 'NaN' values are regarded as
     non-comparable even to themselves, so comparisons involving them
     will always result in 'NA'.
"

i can't find the above explained in the documentation.  typing `<` shows
that it is a

    function(e1, e2) .Primitive("<")

how come can/should it work with no complaint on input that does not
consist of exactly 2 arguments?
in scheme (which is claimed to have been an inspiration for r), < works
on an arbitrary number of arguments:

    (<)
    ;; #t
    (< 1)
    ;; #t
    (< 1 2 3)
    ;; #t
    (< 1 2 0)
    ;; #f

but there < is an arity-dispatched procedure, not a binary one, and it
produces sensible output for any number of arguments (arguably for n=0, 1).

vQ




More information about the R-help mailing list