[R] how to find unique pairs of variables?
Sarah Goslee
sarah.goslee at gmail.com
Thu Sep 15 18:34:45 CEST 2011
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
More information about the R-help
mailing list