A set contains only one copy of each distinct element. Unlike some other programming languages, base R does not have a dedicated data type for sets. Instead, R treats a vector like a set by taking only its distinct elements. This applies to the set operators, setdiff
, intersect
, union
, setequal
and %in%
. For v %in% S
, only S
is treated as a set, however, not the vector v
.
For a true set data type in R, the Rcpp package provides some options.