Check out the unique items.

just a question. I have a data frame (only one vector is shown) that looks like this:

CLN1

b


with
d

....

I need the following output:

CLN1
b
with
d

In other words, I would like to delete all items that are replicated. The unique and duplicate functions return an output, including the replicated item that is presented once. I would like to permanently delete it.

+4
source share
3 answers

You can use setdiff for this:

 R> v <- c(1,1,2,2,3,4,5) R> setdiff(v, v[duplicated(v)]) [1] 3 4 5 
+9
source

You can use count from the plyr package to count the occurrence of an element and remove everyone that happens more than once.

 library(plyr) l = c(1,2,3,3,4,5,6,6,7) count_l = count(l) x freq 1 1 1 2 2 1 3 3 2 4 4 1 5 5 1 6 6 2 7 7 1 l[!l %in% with(count_l, x[freq > 1])] [1] 1 2 4 5 7 

Pay attention to ! which means NOT . You, of course, put this in the oneliner:

 l[!l %in% with(count(l), x[freq > 1])] 
+5
source

Another way: table :

With @juba data:

 as.numeric(names(which(table(v) == 1))) # [1] 3 4 5 

For OP data, since its character output, as.numeric not required.

 names(which(table(v) == 1)) # [1] "b" "c" "d" 
+2
source

All Articles