sets                  package:base                  R Documentation

_S_e_t _O_p_e_r_a_t_i_o_n_s

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

     Performs *set* union, intersection, (asymmetric!) difference,
     equality and membership on two vectors.

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

     union(x, y)
     intersect(x, y)
     setdiff(x, y)
     setequal(x, y)
     is.element(el, set)

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

x, y, el, set: vectors (of the same mode) containing a sequence of
          items (conceptually) with no duplicated values.

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

     Each of 'union', 'intersect' and 'setdiff' will remove any
     duplicated values in the arguments.

     'is.element(x, y)' is identical to 'x %in% y'.

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

     A vector of the same 'mode' as 'x' or 'y' for 'setdiff' and
     'intersect', respectively, and of a common mode for 'union'.

     A logical scalar for 'setequal' and a logical of the same length
     as 'x' for 'is.element'.

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

     '%in%'

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

     (x <- c(sort(sample(1:20, 9)),NA))
     (y <- c(sort(sample(3:23, 7)),NA))
     union(x, y)
     intersect(x, y)
     setdiff(x, y)
     setdiff(y, x)
     setequal(x, y)

     ## True for all possible x & y :
     setequal( union(x,y),
               c(setdiff(x,y), intersect(x,y), setdiff(y,x)))

     is.element(x, y)# length 10
     is.element(y, x)# length  8

