List distinct values in a vector in R

Mehper C. Palavuzlar picture Mehper C. Palavuzlar · Oct 13, 2011 · Viewed 204.1k times · Source

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

Answer

csgillespie picture csgillespie · Oct 13, 2011

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