[R] how to find unique pairs of variables?

Bert Gunter gunter.berton at gene.com
Thu Sep 15 18:39:58 CEST 2011


1. As usual, see FAQ 7.31. unique() may not mean what you think it
means for finite precision numbers:

> unique(c(1/3, sqrt(2)*1/3/sqrt(2)))
[1] 0.3333333 0.3333333

But modulo that: unique(paste(v1,v2))
will give you what you're looking for I think.

-- Bert

On Thu, Sep 15, 2011 at 9:27 AM,  <bby2103 at columbia.edu> wrote:
> I have two variables, both numerical. I would like to find the unique values
> of the pairs, in other words, unique coordinates if I were to plot them.
> I also need to know how many pairs there are, but I guess I can use length()
> if I can somehow isolate the unique pairs first?
> Thanks a lot!
> Bonnie Yuan
> ______________________________________________
> R-help at r-project.org 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.

"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

More information about the R-help mailing list