Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...