To remove a specific item from a set in R, you can use the setdiff function to create a new set without the specified item.
In this example,
number_set
using the set()
function in R, which contains integer values 1
, 2
, 3
, 4
, and 5
.setdiff()
function with number_set
and a vector containing the item 3
to remove the item from the set.number_set <- set(1:5)
number_set <- setdiff(number_set, 3)
print(number_set)
[1] 1 2 4 5
In this example,
char_set
using the set()
function in R, which contains character values 'apple'
, 'banana'
, 'cherry'
, 'date'
, and 'grape'
.setdiff()
function with char_set
and a vector containing the item 'cherry'
to remove the item from the set.char_set <- set(c('apple', 'banana', 'cherry', 'date', 'grape'))
char_set <- setdiff(char_set, 'cherry')
print(char_set)
[1] 'apple' 'banana' 'date' 'grape'
In this tutorial, we learned How to Remove Specific Item from a Set in R language with well detailed examples.