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 or data frame 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, incomparables = FALSE)

_A_r_g_u_m_e_n_t_s:

       x: an atomic vector or a data frame.

incomparables: a vector of values that cannot be compared. Currently,
          `FALSE' is the only possible value, meaning that all values
          can be compared.

_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=TRUE)))
     ## approximately 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)) }

     data(iris)
     unique(iris)
     stopifnot(dim(unique(iris)) == c(149, 5))

