
Compare two data frames. Using a key-column common to both tables, see which rows are common and highlight differing values by column.
Source:R/compare.R
tblcompare.RdCompare two data frames. Using a key-column common to both tables, see which rows are common and highlight differing values by column.
Usage
tblcompare(
.data_a,
.data_b,
by,
allow_bothNA = TRUE,
ncol_by_out = 3,
coerce = TRUE
)
value_diffs(comparison, col)
# S3 method for tbcmp_compare
value_diffs(comparison, col)
all_value_diffs(comparison)
# S3 method for tbcmp_compare
all_value_diffs(comparison)Arguments
- .data_a
A data frame or data table
- .data_b
A data frame or data table
- by
tidy-select. Selection of columns to use when matching rows between
.data_aand.data_b. Both data frames must be unique onby.- allow_bothNA
Logical. If TRUE a missing value in both data frames is considered as equal
- ncol_by_out
Number of by-columns to include in
col_diffsandunmatched_rowsoutput- coerce
Logical. If False only columns with the same class are compared.
- comparison
An object of class "tbcmp_compare" (the output of a
tablecompare::tablecompare()call)- col
tidy-select. A single column
Value
tblcompare()A "tbcmp_compare"-class object, which is a list of
data.table`s having the following elements:- tables
A
data.tablewith one row per input table showing the number of rows and columns in each.- by
A
data.tablewith one row perbycolumn showing the class of the column in each of the input tables.- summ
A
data.tablewith one row per column common to.data_aand.data_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.tableshowing the rows in each input table where values are unequal, the values in each table, and one column for each of the firstncol_by_outbycolumns for the identified rows in the input tables.- unmatched_cols
A
data.tablewith 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.tablewhich, for each row present in one input table but not the other, contains the columns "table": which table the row appears in, "i" the row number of the input row, and one column for each of the firstncol_by_outbycolumns for each row.
value_diffs()A
data.tablewith one row for each element ofcolfound to be unequal between the input tables (.data_aand.data_bfrom the originaltblcompare()call) The output table has columns "i_a"/"i_b": the row number of the element in the input tables, "val_a"/"val_b": the value ofcolin the input tables, and one column for each of the firstncol_by_outbycolumns for the identified rows in the input tables.all_value_diffs()A
data.tableof thevalue_diffs()output for all columns having at least one value difference, combined row-wise into a single table. To facilitate this combination into a single table, the "val_a" and "val_b" columns are coerced to character.