sets {base} R Documentation

## Set Operations

### Description

Performs set union, intersection, (asymmetric!) difference, equality and membership on two vectors.

### Usage

```union(x, y)
intersect(x, y)
setdiff(x, y)
setequal(x, y)

is.element(el, set)
```

### Arguments

 `x, y, el, set` vectors (of the same mode) containing a sequence of items (conceptually) with no duplicated values.

### Details

Each of `union`, `intersect`, `setdiff` and `setequal` will discard any duplicated values in the arguments, and they apply `as.vector` to their arguments (and so in particular coerce factors to character vectors).

`is.element(x, y)` is identical to `x %in% y`.

### Value

A vector of the same `mode` as `x` or `y` for `setdiff` and `intersect`, respectively, and of a common mode for `union`.

A logical scalar for `setequal` and a logical of the same length as `x` for `is.element`.

`%in%`

plotmath’ for the use of `union` and `intersect` in plot annotation.

### Examples

```(x <- c(sort(sample(1:20, 9)), NA))
(y <- c(sort(sample(3:23, 7)), NA))
union(x, y)
intersect(x, y)
setdiff(x, y)
setdiff(y, x)
setequal(x, y)

## True for all possible x & y :
setequal( union(x, y),
c(setdiff(x, y), intersect(x, y), setdiff(y, x)))

is.element(x, y) # length 10
is.element(y, x) # length  8
```

[Package base version 4.0.2 Index]
{"ft_lang_label":"__label__en","ft_lang_prob":0.5884447,"math_prob":0.9759262,"size":1147,"snap":"2021-21-2021-25","text_gpt3_token_len":342,"char_repetition_ratio":0.1583552,"word_repetition_ratio":0.021505376,"special_character_ratio":0.29206625,"punctuation_ratio":0.2007722,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9973981,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-07T20:23:28Z\",\"WARC-Record-ID\":\"<urn:uuid:4f7e4503-16cb-4dc0-ae95-5a534e426053>\",\"Content-Length\":\"2783\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:db947766-24a2-4683-8bf6-cdb5a325c731>\",\"WARC-Concurrent-To\":\"<urn:uuid:92099c57-4444-4e2e-981e-0b034c397282>\",\"WARC-IP-Address\":\"129.132.119.195\",\"WARC-Target-URI\":\"https://stat.ethz.ch/R-manual/R-patched/library/base/html/sets.html\",\"WARC-Payload-Digest\":\"sha1:QHBNJUQV6DEL2LUIGPWKBJSQU6OTXMSP\",\"WARC-Block-Digest\":\"sha1:WUQDARIGEZJ6NW6EKCLOHV7HTJS4JX2G\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243988802.93_warc_CC-MAIN-20210507181103-20210507211103-00548.warc.gz\"}"}