
Obtain differences between two data frames
compare_df(dfcomp_x, dfcomp_y, keys_x, keys_y = NA, compare_values = FALSE)
first data frame to compare
second data frame to compare
keys of the first dataframe
(optional) keys of the second dataframe, if missing both data frames will be compared with the keys_x
(optional) if TRUE it will not only compare keys, but also will check if the values of non-key matching columns have the same values
Differences and coincident values
# NOT RUN {
data(heart_disease)
a=heart_disease
b=heart_disease
a=subset(a, age >45)
b=subset(b, age <50)
b$gender='male'
b$chest_pain=ifelse(b$chest_pain ==3, 4, b$chest_pain)
res=compare_df(a, b, c('age', 'gender'))
# Print the keys that didn't match
res
# Accessing the keys not present in the first data frame
res[[1]]$rows_not_in_X
# Accessing the keys not present in the second data frame
res[[1]]$rows_not_in_Y
# Accessing the keys which coincide completely
res[[1]]$coincident
# Accessing the rows whose values did not coincide
res[[1]]$different_values
# }
Run the code above in your browser using DataLab