Peng Yu
2009-Dec-01 03:42 UTC
[R] Is there a function to test if all the elements in a vector are unique
length(unique(c(1,2,2)))==length(c(1,2,2)) I use the above test to test if all the elements in a vector are unique. But I'm wondering if there is a convenient function to do so in R library.
Ista Zahn
2009-Dec-01 03:47 UTC
[R] Is there a function to test if all the elements in a vector are unique
See ?duplicated. But really I don't see anything wrong with your approach. -Ista On Mon, Nov 30, 2009 at 10:42 PM, Peng Yu <pengyu.ut at gmail.com> wrote:> length(unique(c(1,2,2)))==length(c(1,2,2)) > > I use the above test to test if all the elements in a vector are > unique. But I'm wondering if there is a convenient function to do so > in R library. > > ______________________________________________ > 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. >-- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org
Remko Duursma
2009-Dec-01 03:48 UTC
[R] Is there a function to test if all the elements in a vector are unique
any(duplicated(c(1,2,2))) r ------------------------------------------------- Remko Duursma Post-Doctoral Fellow Centre for Plants and the Environment University of Western Sydney Hawkesbury Campus Richmond NSW 2753 Dept of Biological Science Macquarie University North Ryde NSW 2109 Australia Mobile: +61 (0)422 096908 www.remkoduursma.com On Tue, Dec 1, 2009 at 2:42 PM, Peng Yu <pengyu.ut at gmail.com> wrote:> length(unique(c(1,2,2)))==length(c(1,2,2)) > > I use the above test to test if all the elements in a vector are > unique. But I'm wondering if there is a convenient function to do so > in R library. > > ______________________________________________ > 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. >
Karl Ove Hufthammer
2009-Dec-01 07:40 UTC
[R] Is there a function to test if all the elements in a vector are unique
On Tue, 1 Dec 2009 14:48:04 +1100 Remko Duursma <remkoduursma at gmail.com> wrote:> any(duplicated(c(1,2,2)))or anyDuplicated(c(1,2,2)) which is slightly more efficient. -- Karl Ove Hufthammer
Petr PIKAL
2009-Dec-01 08:19 UTC
[R] Odp: Is there a function to test if all the elements in a vector are unique
Hi r-help-bounces at r-project.org napsal dne 01.12.2009 04:42:31:> length(unique(c(1,2,2)))==length(c(1,2,2)) > > I use the above test to test if all the elements in a vector are > unique. But I'm wondering if there is a convenient function to do so > in R library.maybe any(duplicated(c(1,2,2))) Regards Petr> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.