diff_check {supportR}R Documentation

Compare Difference Between Two Vectors

Description

Reflexively compares two vectors and identifies (1) elements that are found in the first but not the second (i.e., "lost" components) and (2) elements that are found in the second but not the first (i.e., "gained" components). This is particularly helpful when manipulating a dataframe and comparing what columns are lost or gained between wrangling steps. Alternately it can compare the contents of two columns to see how two dataframes differ.

Usage

diff_check(old = NULL, new = NULL, sort = TRUE, return = FALSE)

Arguments

old

(vector) starting / original object

new

(vector) ending / modified object

sort

(logical) whether to sort the difference between the two vectors

return

(logical) whether to return the two vectors as a 2-element list

Value

No return value (unless return = TRUE), called for side effects. If return = TRUE, returns a two-element list

Examples

# Make two vectors
vec1 <- c("x", "a", "b")
vec2 <- c("y", "z", "a")

# Compare them!
diff_check(old = vec1, new = vec2, return = FALSE)

# Return the difference for later use
diff_out <- diff_check(old = vec1, new = vec2, return = TRUE)
diff_out


[Package supportR version 1.3.0 Index]