Comparison               package:base               R Documentation

_R_e_l_a_t_i_o_n_a_l _O_p_e_r_a_t_o_r_s

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

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

_D_e_t_a_i_l_s:

     The binary comparison operators are generic functions: methods can
     be written for them individually or via the 'Ops') group generic
     function.  (See 'Ops' for how dispatch is computed.)

     Comparison of strings in character vectors is lexicographic within
     the strings using the collating sequence of the locale in use: see
     'locales'.  The collating sequence of locales such as 'en_US' is
     normally different from 'C' (which should use ASCII) and can be
     surprising.

     At least one of 'x' and 'y' must be an atomic vector, but if the
     other is a list R attempts to coerce it to the type of the atomic
     vector: this will succeed if the list is made up of elements of
     length one that can be coerced to the correct type.

     If the two arguments are atomic vectors of different types, one is
     coerced to the type of the other, the (decreasing) order of
     precedence being character, complex, numeric, integer, logical and
     raw.

     When comparisons are made between character strings, parts of the
     strings after embedded 'nul' characters are ignored.  (This is
     necessary as the position of 'nul' in the collation sequence is
     undefined, and we want one of '<', '==' and '>' to be true for any
     comparison.)

     Missing values ('NA') and 'NaN' values are regarded as
     non-comparable even to themselves, so comparisons involving them
     will always result in 'NA'.  Missing values can also result when
     character strings are compared and one is not valid in the current
     collation locale.

_V_a_l_u_e:

     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.

_N_o_t_e:

     Do not 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 and complex 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.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     'factor' for the behaviour with factor arguments.

     'Syntax' for operator precedence.

_E_x_a_m_p_l_e_s:

     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

