Compares two data frames row-by-row based on a key column, identifying rows present in only one of the two frames and columns that differ in matched rows.
Value
a named list with four elements:
identicallogical.
TRUEif the two data frames are identical with respect to the common columns and key.onlyInXdata frame of rows whose key value appears in
xbut not iny.onlyInYdata frame of rows whose key value appears in
ybut not inx.diffsdata frame with columns named after the
keyargument (the key value) anddiffCols(a list column of character vectors naming the differing columns for that key).
Details
Only columns present in both data frames are compared. Rows are matched by
the key column using identical() for element-wise comparison,
so type differences (e.g., integer vs. double) will be flagged
as differences.
The values of the key column must be unique in both data frames.
See also
Other data.equal:
allDuplicated(),
allIdentical()
Examples
x <- data.frame(id = c("A", "B", "C"), v1 = 1:3, v2 = c(10, 20, 30))
y <- data.frame(id = c("A", "B", "D"), v1 = c(1L, 9L, 4L), v2 = c(10, 20, 40))
compareDataFrames(x, y, key = "id")
#> $identical
#> [1] FALSE
#>
#> $onlyInX
#> id v1 v2
#> 3 C 3 30
#>
#> $onlyInY
#> id v1 v2
#> 3 D 4 40
#>
#> $diffs
#> id diffCols
#> 1 B v1
#>
