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.

     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.

_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:

     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.

_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:

     '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

