pmatch                 package:base                 R Documentation

_P_a_r_t_i_a_l _S_t_r_i_n_g _M_a_t_c_h_i_n_g

_D_e_s_c_r_i_p_t_i_o_n:

     'pmatch' seeks matches for the elements of its first argument
     among those of its second.

_U_s_a_g_e:

     pmatch(x, table, nomatch = NA, duplicates.ok = FALSE)

_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 returned at non-matching or multiply partially
          matching positions.

duplicates.ok: should elements be in 'table' be used more than once?

_D_e_t_a_i_l_s:

     The behaviour differs by the value of 'duplicates.ok'. Consider
     first the case if this is true.  First exact matches are
     considered, and the positions of the first exact matches are
     recorded. Then unique partial matches are considered, and if found
     recorded. (A partial match occurs if the whole of the element of
     'x' matches the beginning of the element of 'table'.)  Finally,
     all remaining elements of 'x' are regarded as unmatched. In
     addition, an empty string can match nothing, not even an exact
     match to an empty string.  This is the appropriate behaviour for
     partial matching of character indices, for example.

     If 'duplicates.ok' is 'FALSE', values of 'table' once matched are
     excluded from the search for subsequent matches.  This behaviour
     is equivalent to the R algorithm for argument matching, except for
     the consideration of empty strings (which in argument matching are
     matched after exact and partial matching to any remaining
     arguments).

     'charmatch' is similar to 'pmatch' with 'duplicates.ok' true, the
     differences being that it differentiates between no match and an
     ambiguous partial match,  it does match empty strings, and it does
     not allow multiple exact matches.

_V_a_l_u_e:

     A numeric vector of integers (including 'NA' if 'nomatch = NA') of
     the same length as 'x', giving the indices of the elements in
     'table' which matched, or 'nomatch'.

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

     Chambers, J. M. (1998) _Programming with Data. A Guide to the S
     Language_. Springer.

_S_e_e _A_l_s_o:

     'match', 'charmatch' and 'match.arg', 'match.fun', 'match.call',
     for function argument matching etc., 'grep' etc for more general
     (regexp) matching of strings.

_E_x_a_m_p_l_e_s:

     pmatch("", "")                             # returns NA
     pmatch("m",   c("mean", "median", "mode")) # returns NA
     pmatch("med", c("mean", "median", "mode")) # returns 2

     pmatch(c("", "ab", "ab"), c("abc", "ab"), dup=FALSE)
     pmatch(c("", "ab", "ab"), c("abc", "ab"), dup=TRUE)
     ## compare
     charmatch(c("", "ab", "ab"), c("abc", "ab"))

