unique                 package:base                 R Documentation

_E_x_t_r_a_c_t _U_n_i_q_u_e _E_l_e_m_e_n_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     `unique' returns a vector like `x' but with duplicate elements
     removed.  If an element is equal to one with a smaller index, it
     is removed.

_U_s_a_g_e:

     unique(x)

_A_r_g_u_m_e_n_t_s:

       x: an atomic vector

_S_e_e _A_l_s_o:

     `duplicated' which gives the indices of duplicated elements.

_E_x_a_m_p_l_e_s:

     unique(c(3:5, 11:8, 8 + 0:5))
     length(unique(sample(100,100,replace=T)))# ~= 100(1 - 1/e) = 63.21
     my.unique <- function(x) x[!duplicated(x)]
     for(i in 1:4)
      { x <- rpois(100, pi); stopifnot(unique(x) == my.unique(x)) }

