Compare 2 dataframes - number of differences per column

I use R a fair amount for testing. I have used all_equal which is good at finding how many rows differ between dataframes
But I would like to report on the number of differences per column. Is there a function to do that already please?

I know that the 2 dataframes have the same column names in the same order and that the rows are same by key field and in the same order

Turns out that the function is not that difficult to write - albeit not great code quality and no parameter checking
But would love to hear if such a function does exist

DiffPerCol = function(df1, df2) {
  cn = colnames(df1)
  Output = tibble()
  for (c in cn) {
    te = testequal(df1[,c], df2[,c])
    tesum = sum(!te)
    FirstDiff = match(FALSE, te)
    Output = rbind(Output, cbind(column = c, ndifferences = tesum, firstdifference = FirstDiff))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.