{
  "name": "Three R implementations of set difference: input, duplicate handling and result",
  "description": "Compares base R setdiff(), dplyr setdiff() and data.table fsetdiff() on what they accept, how they treat duplicates and what they return, compiled from each package's official reference documentation.",
  "page": "https://casrai.org/guides/setdiff-in-r",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-16T21:58:44Z",
  "temporalCoverage": "2026",
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Function",
      "unit": "",
      "description": ""
    },
    {
      "name": "Package",
      "unit": "",
      "description": ""
    },
    {
      "name": "Input",
      "unit": "",
      "description": ""
    },
    {
      "name": "Duplicate handling",
      "unit": "",
      "description": ""
    },
    {
      "name": "Result",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Function": "setdiff(x, y)",
      "Package": "base R",
      "Input": "Vectors of the same mode",
      "Duplicate handling": "Duplicated values discarded",
      "Result": "Vector with the same mode/class as x (factors keep class from R 4.5.0)"
    },
    {
      "Function": "setdiff(x, y, ...)",
      "Package": "dplyr",
      "Input": "Data frames with the same column names and compatible types",
      "Duplicate handling": "Duplicates removed within x and y",
      "Result": "Rows of x not in y"
    },
    {
      "Function": "fsetdiff(x, y, all = FALSE)",
      "Package": "data.table",
      "Input": "data.tables (no complex or list columns)",
      "Duplicate handling": "Duplicates removed when all = FALSE",
      "Result": "Rows of x not in y, row order retained"
    },
    {
      "Function": "fsetdiff(x, y, all = TRUE)",
      "Package": "data.table",
      "Input": "data.tables (no complex or list columns)",
      "Duplicate handling": "Duplicates kept: max(0, xn - yn) copies",
      "Result": "Rows of x not in y, row order retained"
    }
  ],
  "sources": [
    {
      "title": "Set Operations (R base documentation)",
      "url": "https://stat.ethz.ch/R-manual/R-devel/library/base/html/sets.html",
      "accessed": "2026-11-14"
    },
    {
      "title": "dplyr: Set operations",
      "url": "https://dplyr.tidyverse.org/reference/setops.html",
      "accessed": "2026-11-14"
    },
    {
      "title": "data.table: Set operations",
      "url": "https://rdatatable.gitlab.io/data.table/reference/setops.html",
      "accessed": "2026-11-14"
    }
  ]
}