We list the different values ​​in the vector in R

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

SELECT DISTINCT product_code FROM data 
+61
vector r distinct-values
Oct 13 '11 at 13:57
source share
3 answers

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 
+106
Oct 13 '11 at
source share

You can also use the sqldf package in R. Z <-sqldf ('SELECT DISTINCT tablename.columnname FROM tablename')

+5
Mar 31 '16 at 23:43
source share

Try using a duplicate function in conjunction with the negation operator "!".

Example:

 wdups <- rep(1:5,5) wodups <- wdups[which(!duplicated(wdups))] 

Hope this helps.

+4
Oct. 13 '11 at 2:07 a.m.
source share



All Articles