| compare {versus} | R Documentation |
Compare two data frames
Description
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_*().
Usage
compare(table_a, table_b, by, allow_both_NA = TRUE, coerce = TRUE)
Arguments
table_a |
A data frame |
table_b |
A data frame |
by |
< |
allow_both_NA |
Logical. If |
coerce |
Logical. If |
Value
compare()A list of data frames having the following elements:
- tables
-
A data frame with one row per input table showing the number of rows and columns in each.
- by
-
A data frame with one row per
bycolumn showing the class of the column in each of the input tables. - intersection
-
A data frame with one row per column common to
table_aandtable_band 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 values in each table which are unequal and thebycolumns - unmatched_cols
-
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.
- unmatched_rows
-
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
bycolumns for that row.
data.table inputs
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).
Examples
compare(example_df_a, example_df_b, by = car)