Learn R Programming

supportR (version 1.5.0)

diff_check: 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)

Value

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

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

Examples

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

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

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

Run the code above in your browser using DataLab