Replace duplicated elements with NA, instead of removing them

You were pretty close. I’m not sure what DFl is though. But this works…

DF <- data.frame(A=c("a", "a", "a", "b", "b", "c"))
DF$A[duplicated(DF$A)] <- NA
> DF
     A
1    a
2 <NA>
3 <NA>
4    b
5 <NA>
6    c

Leave a Comment