Symmetric set difference of two data frames

symmetric_setdiff(
  x,
  y,
  xname = "x",
  yname = "y",
  namecol = "source",
  simplify_types = TRUE
)

Arguments

x, y

`data.frame`s to compare

xname

Label for data in x but not y. Default = "x"

yname

Label for data in y but not x. Default = "y"

namecol

Name of label column. Default = "source".

simplify_types

(Logical) If `TRUE`, coerce anything that isn't numeric to character, to facilitate comparison.

Value

`data.frame` of data not common to x and y, with additional column (`namecol`) indicating whether data are only in x (`xname`) or y (`yname`)

Examples

xdf <- data.frame(a = c("a", "b", "c"),
                  b = c(1, 2, 3),
                  stringsAsFactors = FALSE)
ydf <- data.frame(a = c("a", "b", "d"),
                  b = c(1, 2.5, 3),
                  stringsAsFactors = FALSE)
symmetric_setdiff(xdf, ydf)
#>   source a   b
#> 1      x b 2.0
#> 2      x c 3.0
#> 3      y b 2.5
#> 4      y d 3.0