In R, you can add an item to a Set (implemented using the 'set' class from the 'sets' package) using the add() function.
In this example,
numbers
containing some integer elements.6
, to the set.numbers
contains the added element 6
.library(sets)
numbers <- set(1, 2, 3, 4, 5)
numbers <- add(numbers, 6)
print(numbers)
{1, 2, 3, 4, 5, 6}
In this example,
fruits
containing some string elements.'Orange'
, to the set.fruits
contains the added element 'Orange'
.library(sets)
fruits <- set('Apple', 'Banana', 'Cherry')
fruits <- add(fruits, 'Orange')
print(fruits)
{Apple, Banana, Cherry, Orange}
In this tutorial, we learned How to add an Item to a Set in R language with well detailed examples.