Search code examples
rvectordistinct-valuesr-faq

List distinct values in a vector in R


How can I list the distinct values in a vector where the values are replicative? I mean, similarly to the following SQL statement:

SELECT DISTINCT product_code
FROM data

Solution

  • Do you mean unique:

    R> x = c(1,1,2,3,4,4,4)
    R> x
    [1] 1 1 2 3 4 4 4
    R> unique(x)
    [1] 1 2 3 4