Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get "who's different" in a vector, with R

Tags:

r

Simple question. Consider this vector:

[1] 378 380 380 380 380 360 187 380

How could we determine what are the numbers that differs from the others in that list? In that case it would be 378 360 and 187. Any ideas? I'm aware that the solution might not be simple...

I'm learning R and working on a dataset for my research, so it's != homework.

Any help would be greatly appreciated !

like image 597
Chargaff Avatar asked Dec 17 '22 03:12

Chargaff


2 Answers

Maybe another alternative:

x <- c(378, 380, 380, 380, 380, 360, 187, 380)
setdiff(unique(x), x[duplicated(x)])
like image 102
lexlex Avatar answered Jan 06 '23 06:01

lexlex


Extracting unrepeated elements can be done with something like:

a<-c(378, 380, 380, 380, 380, 360, 187, 380)
b <- table(a)
names(b[b==1])
#[1] "187" "360" "378"
like image 34
Ian Fellows Avatar answered Jan 06 '23 06:01

Ian Fellows