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

