Created
December 6, 2018 08:57
-
-
Save peterdalle/f45ac12a7a861aaf6533b4e9c86d2772 to your computer and use it in GitHub Desktop.
Compare two data frames for similarity (and if they are different, print out the differences)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create data. | |
set.seed(1341) | |
original <- data.frame(x = rnorm(10), y = rnorm(10)) | |
change <- original | |
change[5, 1] <- 6 | |
change[7, 2] <- 4 | |
# Function to compare data frames for similarity. | |
compare_data_frames <- function(df1, df2) { | |
if (identical(df1, df2)) { | |
cat("Data frames are identical.") | |
} else { | |
cat("Data frames are not identical.\n\nDifferences:\n") | |
all.equal(df1, df2) | |
} | |
} | |
# Do comparison. | |
compare_data_frames(original, change) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment