[R] Non-unique Values

Polwart Calum (County Durham and Darlington NHS Foundation Trust) calum.polwart at nhs.net
Tue May 25 20:12:01 CEST 2010


I might be missing something really obvious, but is there an easy way to locate all non-unique values in a data frame?

Example

mydata <- numeric()
mydata$id <- 0:8
mydata$unique <- c(1:5, 1:4)
mydata$result <- c(1:3, 1:3, 1:3)

> mydata
$id
 [1] 0 1 2 3 4 5 6 7 8
$unique
[1] 1 2 3 4 5 1 2 3 4
$result
[1] 1 2 3 1 2 3 1 2 3

What I want to to be able to get some form of data output that might look like this:

> nonunique(mydata$unique)
mydata$unique
1  $id 0, 5
2  $id 1, 6
3  $id 2, 7
4  $id 3, 8

So that I could report to my data entry team any non-unique values of unique and tell them the row numbers so they can check if the 'unique' value is keyed wrongly, or the entry had been made twice.

Hoping there is an easy way.  if not I suspect we can do it in the SQL tables, just trying not to juggle two languages...

C

********************************************************************************************************************

This message may contain confidential information. If yo...{{dropped:21}}



More information about the R-help mailing list