Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)

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

1 Answer

0 votes
by

You can use the unique function from the base package that returns a vector, data frame or array-like x but with duplicate elements/rows removed.

For example:

x = c(1,1,2,2,3,3,4,4,4)

> x

[1] 1 1 2 2 3 3 4 4 4

> unique(x)

[1] 1 2 3 4

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...