Re: [R] Finding a single unique item in duplicated vectors

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Wed 04 Apr 2007 - 17:23:35 GMT


Arrgh! I knew it going to be was blindingly obvious once someone showed it to me. I had even looked at diff() at one point but never found setdiff. ?sets did not seem to find anything.

Thanks very much.

> On Wed, 4 Apr 2007, John Kane wrote:
>
> > I have a very simple problem and am completely
> missing
> > the solution.
> > I have two character variables (character ID's
> from
> > two datasets) Data set 'b'
> > is data set 'a' with one more subject added.
> > How do I find out which is the added subject?
>
>
> setdiff( b, a ) ??
>
> >
> > I have tried duplicated and unique without much
> > success. I can find all the
> > duplicated ID's but how do I extract the new
> "unique"
> > one?
> > Example:
> > a <- as.character(Cs(b,d,c,a))
> > b <- as.character( Cs(a,b,c,d,e))
> > h <- c(a,b) ; h
> > h[duplicated(h)]
> >
> > I just want to extract that "e"!
> >
> > I had thought that
> > h[!duplicated(h)]
> > might work but it simply returns all the unique
> values
> > whereas
> > I simply want to simply find the odd man out.
> >
> > I thought of using sorting the vectors & using a
> cbind
> > but the id's are assigned
> > more or less randomly so that didn't work.
> >
> > Thanks
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained,
> reproducible code.
> >
>
> Charles C. Berry (858)
> 534-2098
> Dept of
> Family/Preventive Medicine
> E mailto:cberry@tajo.ucsd.edu UC San Diego
> http://biostat.ucsd.edu/~cberry/ La Jolla,
> San Diego 92093-0901
>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Apr 05 03:35:09 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 04 Apr 2007 - 18:30:56 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.