Comparison               package:base               R Documentation

Relational Operators

Description:

     Binary operators which allow the comparison of values in vectors.

Usage:

     x < y
     x > y
     x <= y
     x >= y
     x == y
     x != y

Value:

     A vector of logicals indicating the result of the element by
     element comparison.  The elements of shorter vectors are recycled
     as necessary.

     Objects such as arrays or time-series can be compared this way
     provided they are conformable.

Note:

     Don't use `==' and `!=' for tests, such as in `if' expressions,
     where you must get a single `TRUE' or `FALSE'.  Unless you are
     absolutely sure that nothing unusual can happen, you should use
     the `identical' function instead.

     For numerical values, remember `==' and `!=' do not allow for the
     finite representation of fractions, nor for rounding error. Using
     `all.equal' with `identical' is almost always preferable. See the
     examples.

Examples:

     x <- rnorm(20)
     x < 1
     x[x > 0]

     x1 <- 0.5 - 0.3
     x2 <- 0.3 - 0.1
     x1 == x2                           # FALSE on most machines
     identical(all.equal(x1, x2), TRUE) # TRUE everywhere

