I am trying to find elements that are not common to multiple vectors. That is, I want to know exactly the elements (and not just their position, etc.), which are not divided by all vectors.
The best implementation I could use uses a nested loop, which, as I understand it, is perhaps the least efficient, especially because the execution is still running when I write this. Here is what I came up with. (each * .id is a vector of the identifier of the Supreme Court case, stored as strings).
check.cases<-TRUE if(check.cases) { all.cases<-c(AMKennedy.id,AScalia.id,CThomas.id,DHSouter.id,JGRoberts.id,JPStevens.id,RBGinsburg.id,SAAlito.id,SGBreyer.id) bad.cases<-c() for(b in all.cases) { for(t in all.cases) { m<-match(t,b) bad<-t[which(is.na(m))] bad.cases<-append(bad.cases,bad) } } bad.cases<-unique(bad.cases) } print(bad.cases)
Should there be a more efficient way to do this?
vector search r
DrewConway
source share