I have a DF
. One of its columns looks like
DF$A
A
a
a
a
b
b
b
c
c
I am trying to replace all duplicated characters in this column with NA
.
Naively, I tried
DF$A <- DFl[duplicated(DF$A),] <- NA
But it just converts whole DF to NA
values. Thank you for any suggestion.
Remove Duplicate rows in R using Dplyr – distinct () function. Distinct function in R is used to remove duplicate rows in R using Dplyr package. Dplyr package in R is provided with distinct() function which eliminate duplicates rows with single variable or with multiple variable.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With