I have a network table saved as csv file(data frame) looking like this:
a b 1
b a 3
a c 2
a d 2
c a 2
I want to save the repeated pair of value, in this case
a b 1
b a 3
should be saved as following:
a b
a c
Other values should be omitted. How can I achieve this in R? Thanks in advance!
updated: My file is also really large (about 100MB, probably 70 thousand rows), so I need a solution that can run fast. I try to sort first then check duplicate, but it is too slow.
Here is my code:
ud <- function(df){
df[1:2] <- t( apply(df[1:2], 1, sort) )
out <- df[duplicated(df[1:2]),]
out[3] <- NULL
write.table(out, file="D:/out.txt", sep=" ", row.names=FALSE, col.names=FALSE)
}