make.unique               package:base               R Documentation

_M_a_k_e _C_h_a_r_a_c_t_e_r _S_t_r_i_n_g_s _U_n_i_q_u_e

_D_e_s_c_r_i_p_t_i_o_n:

     Makes the elements of a character vector unique by appending
     sequence numbers to duplicates.

_U_s_a_g_e:

     make.unique(names, sep = ".")

_A_r_g_u_m_e_n_t_s:

   names: a character vector

     sep: a character string used to separate a duplicate name from its
          sequence number.

_D_e_t_a_i_l_s:

     The algorithm used by 'make.unique' has the property that
     'make.unique(c(A, B)) == make.unique(c(make.unique(A), B))'.

     In other words, you can append one string at a time to a vector,
     making it unique each time, and get the same result as applying
     'make.unique' to all of the strings at once.

     If character vector 'A' is already unique, then 'make.unique(c(A,
     B))' preserves 'A'.

_V_a_l_u_e:

     A character vector of same length as 'names' with duplicates
     changed, in the current locale's encoding.

_A_u_t_h_o_r(_s):

     Thomas P. Minka

_S_e_e _A_l_s_o:

     'make.names'

_E_x_a_m_p_l_e_s:

     make.unique(c("a", "a", "a"))
     make.unique(c(make.unique(c("a", "a")), "a"))

     make.unique(c("a", "a", "a.2", "a"))
     make.unique(c(make.unique(c("a", "a")), "a.2", "a"))

     rbind(data.frame(x=1), data.frame(x=2), data.frame(x=3))
     rbind(rbind(data.frame(x=1), data.frame(x=2)), data.frame(x=3))

