This may be redundant for your problem, but you can also look into compare() from the "compare" pacakge. Consider the following examples:
> data <- data.frame(A = c(1, 2, 3, 4), B = c(1, 2, 3, 4)) > compare(data[1], data[2]) ## Should be false FALSE [TRUE] > compare(data[1], data[2], ignoreNames = TRUE) # Allow different names TRUE dropped names > data <- data.frame(A = c(1, 2, 3, 4), B = as.character(c(1, 2, 3, 4))) > str(data) ## "B" is now a factor, so use `coerce` to test for equality 'data.frame': 4 obs. of 2 variables: $ A: num 1 2 3 4 $ B: Factor w/ 4 levels "1","2","3","4": 1 2 3 4 > compare(data[1], data[2], ignoreNames = TRUE, coerce = TRUE) TRUE [A] coerced from <factor> to <numeric> dropped names
There is a common boolean argument allowAll , which can be set to TRUE to allow the compare function to try various transformations to check for equality.
source share