compare_df {COINr}R Documentation

Compare two data frames


A custom function for comparing two data frames of indicator data, to see whether they match up, at a specified number of significant figures. Specifically, this is intended to compare two data frames, without regard to row or column ordering. Rows are matched by the required matchcol argument. Hence, it is different from e.g. all.equal() which requires rows to be ordered. In COINr, typically matchcol is the uCode column, for example.


compare_df(df1, df2, matchcol, sigfigs = 5)



A data frame


Another data frame


A common column name that is used to match row order. E.g. this might be uCode.


The number of significant figures to use for matching numerical columns


This function compares numerical and non-numerical columns to see if they match. Rows and columns can be in any order. The function performs the following checks:

It then summarises for each column whether there are any differences, and also what the differences are, if any.

This is intended to cross-check results. For example, if you run something in COINr and want to check indicator results against external calculations.

This function replaces the now-defunct compareDF() from COINr < v1.0.


A list with comparison results. List contains:


# take a sample of indicator data (including the uCode column)
data1 <- ASEM_iData[c(2,12:15)]
# copy the data
data2 <- data1
# make a change: replace one value in data2 by NA
data2[1,2] <- NA
# compare data frames
compare_df(data1, data2, matchcol = "uCode")

[Package COINr version 1.1.7 Index]