[R] how to find unique pairs of variables?

Bert Gunter gunter.berton at gene.com
Thu Sep 15 18:42:30 CEST 2011


 I should try reading the Help page!  Please ignore my prior "advice"
-- except for the party about FAQ 7.31, which may still apply, of
course.

-- Bert

On Thu, Sep 15, 2011 at 9:34 AM, Sarah Goslee <sarah.goslee at gmail.com> wrote:
> Hi Bonnie,
>
> ?unique probably would have done the trick for you. But here's an
> example:
>> z <- data.frame(x = rep(1:5, each=2), y = rep(1:2, each=5))
>> z
>   x y
> 1  1 1
> 2  1 1
> 3  2 1
> 4  2 1
> 5  3 1
> 6  3 2
> 7  4 2
> 8  4 2
> 9  5 2
> 10 5 2
>> unique(z)
>  x y
> 1 1 1
> 3 2 1
> 5 3 1
> 6 3 2
> 7 4 2
> 9 5 2
>> nrow(unique(z))
> [1] 6
>
> Sarah
>
>
> On Thu, Sep 15, 2011 at 12:27 PM,  <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.
>>
>
>
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> ______________________________________________
> 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
467-7374
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list