R: Comparing different versions of data in terms of levels

Viewed 34

my aim is to compare differences in levels of variables that might occur across different versions of a dataset. In my code, I first generate strings in order to be able to compare several variables (numeric, categorical, etc.). However, the code fails and does not give the desired results, which would be a data frame that consists of the variable and possible differences (in a list). Any help is appreciated!

Thank you.

data1 <- lapply(?, as.character)
data2 <- lapply(?, as.character)

check_diffs <- function(vars, data1, data2) {
  levels1 <- unique(data1$vars)
  levels2 <- unique(data2$vars)
  diff <- ifelse(length(union(setdiff(levels1,levels2), setdiff(levels2,levels1)))>0, list(union(setdiff(levels1,levels2), setdiff(levels2,levels1))), NA)
  return(data.frame(var = vars, diffs = I(diff))) 
}


diffs_df <- map_dfr(vars, ~check_diffs(.x, data1 = ?, data2 = ?))

1 Answers

The issue with the code was that vars gives a string, which must be called with get(vars, dataX). Then, the code gives the differences in coding between both data sets.

Related