diff_check | R Documentation |
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.
diff_check(old = NULL, new = NULL, sort = TRUE, return = FALSE)
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 |
No return value (unless return = TRUE
), called for side effects. If return = TRUE
, returns a two-element list
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.