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 mutliply 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.  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'.

_N_o_t_e:

     Versions of R prior to 1.0.0 had a different behaviour that was
     seriously incompatible with S (and the current version) when
     `duplicates.ok = TRUE'.

_A_u_t_h_o_r(_s):

     Of this version, B. D. Ripley.

_S_e_e _A_l_s_o:

     `match', `charmatch' and `match.arg', `match.fun', `match.call',
     for function argument matching etc.

_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=F)
     pmatch(c("", "ab", "ab"), c("abc", "ab"), dup=T)
     ## compare
     charmatch(c("", "ab", "ab"), c("abc", "ab"))

