This function checks for mismatches between a specified column in two dataframes using the setdiff() function.
It provides detailed feedback on whether the column values match between the two dataframes, and highlights any discrepancies.
Value
The function does not return any value, but prints messages about column matching and discrepancies to the console.
Details
The function compares the values in a specified column from two dataframes:
If all values match, it prints a confirmation message that the dataframes are ready for further data wrangling.
If there are mismatches, the function checks the number of mismatched values in each dataframe and provides details on where the discrepancies lie.
If both dataframes have the same number of mismatches, it suggests the possibility of typos.
Examples
# Example usage:
df1 <- data.frame(ID = c(1, 2, 3, 4), Name = c("Alice", "Bob", "Charlie", "David"))
df2 <- data.frame(ID = c(1, 2, 4, 5), Name = c("Alice", "Bob", "Charlie", "Eve"))
# Verify column match for 'ID'
verify_col_match(df1, df2, col = "ID")
#> The number of mis-matched values in the first and second dataframes are the same. Take special attention when ensuring a match, these could be the result of typos!
#>
#> The mis-matched values from the first dataframe are: 3
#>
#> The mis-matched values from the second dataframe are: 5
# Verify column match for 'Name'
verify_col_match(df1, df2, col = "Name")
#> The number of mis-matched values in the first and second dataframes are the same. Take special attention when ensuring a match, these could be the result of typos!
#>
#> The mis-matched values from the first dataframe are: David
#>
#> The mis-matched values from the second dataframe are: Eve