compare() creates a representation of the differences between two tables,
along with a shallow copy of the tables. This output is used
as the comparison argument when exploring the differences further with other
versus functions e.g. slice_*() and weave_*().
compare(
table_a,
table_b,
by,
allow_both_NA = TRUE,
coerce = TRUE,
table_id = c("a", "b")
)compare()A list of data frames having the following elements:
A data frame with one row per input table showing the number of rows and columns in each.
A data frame with one row per by column showing the class
of the column in each of the input tables.
A data frame with one row per column common to table_a and
table_b and columns "n_diffs" showing the number of values which
are different between the two tables, "class_a"/"class_b" the class of the
column in each table, and "value_diffs" a (nested) data frame showing
the the row indices with differing values
A data frame with one row per column which is in one input table but not the other and columns "table": which table the column appears in, "column": the name of the column, and "class": the class of the column.
A data frame which, for each row present in one input table but not
the other, contains the column "table" showing which table the row appears
in and the by columns for that row.
A data frame
A data frame
<tidy-select>. Selection of columns to use when matching rows between
table_a and table_b. Both data frames must be unique on by.
Logical. If TRUE a missing value in both data frames is
considered as equal
Logical. If FALSE and columns from the input tables have
differing classes, the function throws an error.
A character vector of length 2 providing custom identifiers for
table_a and table_b respectively. These identifiers are used in the
output instead of the default "a" and "b".
If the input is a data.table, you may want compare() to make a deep copy instead
of a shallow copy so that future changes to the table don't affect the comparison.
To achieve this, you can set options(versus.copy_data_table = TRUE).
compare(example_df_a, example_df_b, by = car)
Run the code above in your browser using DataLab