View source: R/exploratory_data_analysis.R
compare_df | R Documentation |
Obtain differences between two data frames
compare_df(dfcomp_x, dfcomp_y, keys_x, keys_y = NA, compare_values = FALSE)
dfcomp_x |
first data frame to compare |
dfcomp_y |
second data frame to compare |
keys_x |
keys of the first dataframe |
keys_y |
(optional) keys of the second dataframe, if missing both data frames will be compared with the keys_x |
compare_values |
(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
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.