In R, you can access items in a set using iteration or specific functions provided by the set data structure.
In this example,
string_set
containing strings.string_set <- c("Apple", "Banana", "Orange", "Grapes")
for (item in string_set) {
print(item)
}
Apple Banana Orange Grapes
In this example,
number_set
containing integers.length
function to get the number of elements in the set.%in%
operator to check if an item exists in the set.number_set <- c(1, 2, 3, 4)
print(length(number_set))
print(3 %in% number_set)
[1] 4 [1] TRUE
In this tutorial, we learned How to Access Items in a Set in R language with well detailed examples.