match                  package:base                  R Documentation

_V_a_l_u_e _M_a_t_c_h_i_n_g

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

     `match': If `x[i]' is found to equal `table[j]' then the value
     returned in the `i'-th position of the return value is `j'.  If no
     match is found, the value is `nomatch'.

     `%in%': A utility function, currently defined as 
     `"%in%" <- function(x, table) match(x, table, nomatch = 0) > 0'
     allowing an intuitive usage and returning a logical vector of
     length `length(x)'.

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

     match(x, table, nomatch=NA)
     x %in% table

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

       x: the values to be matched.

   table: the values to be matched against.

 nomatch: the value to be returned in the case when no match is found.

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

     `pmatch' and `charmatch' for (partial) string matching,
     `match.arg', etc for function argument matching.

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

     ## The intersection of two sets :
     intersect <- function(x, y) y[match(x, y, nomatch = 0)]
     intersect(1:10,7:20)

     1:10 %in% c(1,3,5,9)
     sstr <- c("c","ab","B","bba","c","@","bla","a","Ba","%")
     sstr[sstr %in% c(letters,LETTERS)]

     "%w/o%" <- function(x,y) x[!x %in% y] #--  x without y
     (1:10) %w/o% c(3,7,12)

