0
set.seed(123)
df <- data.frame(
    x = sample(0:2, 10, replace = T),
    y = sample(0:2, 10, replace = T)
)
df[df==2] <- NA

df=df[!duplicated(df$y),]
print(df)

The output of above script is:

  x  y
1  0 NA
2 NA  1
5 NA  0

I want to keep all NA,only compare the valid value.
The expect result is:

    x  y
1   0 NA
2  NA  1
3   1 NA
5  NA  0
6   0 NA
10  1 NA

How to do it? Thanks in advance!

kittygirl
  • 2,255
  • 5
  • 24
  • 52

0 Answers0