To find rows in the first object that are not present in the second object, you can use the compare function from the compare package that compares two objects and, if they are not the same, attempt to transform them to see if they are the same after being transformed.
The compare function is flexible in terms of what kind of comparisons are allowed (e.g. changing order of elements of each vector, changing the order and names of variables, shortening variables, changing the case of strings).
Arguments:
model
The “correct” object.
comparison
The object to be compared with the model.
allowAll
Allow any sort of transformation
In your case:
install.packages(“compare”)
library(“compare”)
a1 <- data.frame(a = 1:5, b = letters[1:5])
a2 <- data.frame(a = 1:3, b = letters[1:3])
To find similar rows:
comp <- compare(a1,a2,allowAll=TRUE)
comp$tM
a b
1 1 a
2 2 b
3 3 c
To find missing rows:
missing <-data.frame(lapply(1:ncol(a1),function(x) setdiff(a1[,x],comp$tM[,x])))
colnames(missing) <- colnames(a1)
missing
a b
1 4 d
2 5 e