On Thu, 14 Aug 2008, Steven McKinney wrote:
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: Thursday, August 14, 2008 2:00 PM
To: r-help@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
Caveat:
length(unique( c(1, NA )))
[1] 2
which may not be what Kevin wants.
Alternatives:
length( na.omit( unique( c(1, NA ) )) ) == 1
!isTRUE( any( a[1] != a[-1] )
HTH,
Chuck
Steve McKinney
Thank you.
Kevin
______________________________________________
R-help@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.
______________________________________________
R-help@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.
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED] UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
______________________________________________
R-help@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.