0 votes
1 view
in R Programming by (5.2k 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 (25.3k points)

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 !


Categories

...