Comparing two data and displaying unique values

I have two data frames,

A(514 rows)

1 2
2 3      
4 5
1 3
5 6
...

B(696 rows)

1 2
3 4
4 5
1 3
5 7
5 6
.....

I want to get these rows and their corresponding columns that are present in B but not in A. For example, the result will be,

3 4
5 7

How to do it in R?

I tried using this post: Compare two data.frames to find rows in data.frame 1 that are not in data.frame 2

But here the first difference of the answers does not give the correct conclusion.

0
source share
1 answer

Try:

colIndx <- colnames(B)[colnames(B) %in% colnames(A)]
rowIndx <- !as.character(interaction(B)) %in%  as.character(interaction(A[colIndx]))
 B[rowIndx,]
#   V1 V2
#2  3  4
#5  5  7

data

 A <- structure(list(V1 = c(1L, 2L, 4L, 1L, 5L), V2 = c(2L, 3L, 5L, 
 3L, 6L)), .Names = c("V1", "V2"), class = "data.frame", row.names = c(NA, 
-5L))

 B <- structure(list(V1 = c(1L, 3L, 4L, 1L, 5L, 5L), V2 = c(2L, 4L, 
 5L, 3L, 7L, 6L)), .Names = c("V1", "V2"), class = "data.frame", row.names = c(NA, 
-6L))
0
source

Source: https://habr.com/ru/post/1667182/


All Articles