Does R have a Set data structure?

Viewed 9456

I am a beginner R learner, so bear with me if I say something incoherent.

I have a large vector variable holding exactly 5000 elements, and would like to know what these are, knowing that there are several repetitions. An introduction to R doesn't seem to say anything besides basic data structures, and I don't know if R offers this feature as built-in.

If there is no such "data structure", is there some built-in function to filter out repeated elements in a vector or list?

5 Answers

I'd also recommend looking into the sets library. Install it with install.packages('sets') and see, if the following works for you.

sets::as.set(c(1, 1, 2, 4, 3, 5, 5, 5))
# output: {1, 2, 3, 4, 5}

R doesn't have a built-in set data structure, you need to download a library called sets. for more information about sets library visit : https://www.rdocumentation.org/packages/sets/versions/1.0-21/topics/set

library('sets')
x <- c(1,2,3,3,4,5,5,6)
x <- c(1,2,3,3)
x <- as.set(x)
y <- as.set(y)
make_set_with_order(x)
is.set(x)
set_is_empty(x)
set_is_subset(x, y)
set_is_proper_subset(x, y)
set_is_equal(x, y)
set_contains_element(x, e)

set_union(…)
set_intersection(…)
set_symdiff(…)
set_complement(x, y)
Related