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

