Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine index of elements in a vector which occur only once

Tags:

r

I have a vector e.g. like this:

vec <- c(6, 6, 10, 13, 13, 15, 15, 15, 15, 16, 16, 19)

I want now the positions of the elements which occur only once:

3, 12

Unique only ignores the values when they already have occurred.

like image 663
FRV Avatar asked Dec 03 '22 17:12

FRV


2 Answers

Another option:

which(!(vec %in% vec[duplicated(vec)]))
#[1]  3 12
like image 117
Roland Avatar answered May 01 '23 02:05

Roland


you can try this

 which(vec %in%  names(table(vec))[table(vec)==1] )
# 3 12
like image 31
Mamoun Benghezal Avatar answered May 01 '23 01:05

Mamoun Benghezal