Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205343

Remove all duplicates based on different columns and rows in R

$
0
0

I have this condition:

    ID  N1      N2
    1   6387    6187 
    2   6290    6386 
    3   6295    6295 
    4   6043    6392 
    5   6042    6043
    6   6050    6031 
    7   6050    6036 
    8   6321    6434 
    9   6440    6397

with duplicates in different columns and rows, and I would like to remove ALL duplicates in N1 and N2, like this:

ID  N1      N2
1   6387    6187 
2   6290    6386 
8   6321    6434 
9   6440    6397

I tried these codes:

dt[(duplicated(dt[,2:3]) | duplicated(dt[,2:3], fromLast = TRUE)), ]

and

library(dplyr)
dt %>% distinct(N1,N2, .keep_all = TRUE)

But didn't work.


Viewing all articles
Browse latest Browse all 205343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>