[R] Detecting duplicate values
Steven McKinney
smckinney at bccrc.ca
Fri Aug 15 03:25:02 CEST 2008
> -----Original Message-----
> From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org]
> On Behalf Of rkevinburton at charter.net
> Sent: Thursday, August 14, 2008 2:00 PM
> To: r-help at r-project.org
> Subject: [R] Detecting duplicate values
>
> This is another "how do I do it" type of question. It seems that for a
> function that I have it has a hard time with lists that have a single
> repeated value. I want a function (or expression) that will detect
this
> condition. I want to detect:
>
> c(2,2,2,2,2)
> OR
> c(1)
>
> The following is OK
>
> c(2,3,3,2)
> OR
> c(1,2,1)
>
> These lists are "OK" because they have another value in the list. In
other
> words I want to detect if there is only one element in the list that
> repeats 1 or more times.
>
> Will length(table(a)) = 1 always work? If so I have answered my own
> question. If not please bear with me as I have missed a case.
Consider also
length(unique(a)) == 1
Steve McKinney
>
> Thank you.
>
> Kevin
>
> ______________________________________________
> 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.
More information about the R-help
mailing list