[R] Detecting duplicate values

rkevinburton at charter.net rkevinburton at charter.net
Thu Aug 14 23:00:22 CEST 2008


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.

Thank you.

Kevin



More information about the R-help mailing list