Search code examples
rduplicate-datamissing-data

How to view duplicated records with one or more NA's?


my dataset looks like following:

ID Score
A1 60
A1 50
A1 NA
B1 30
B1 33
C1 48
C1 39
D1 21
D1 38
D1 NA

I would like to see duplicated records which has NA's. Such as:

A1 60
A1 50
A1 NA
D1 21
D1 38
D1 NA

Thanks for your time and kind consideration...


Solution

  • There might be a slightly neater way to do this:

    df <- data.frame(ID=rep(c("A1", "B1", "C1"), each=4), Score=sample(1:100,12))
    df$Score[c(1,7)] <- NA
    
    df[df$ID %in% df$ID[which(is.na(df$Score))],]