To remove duplicates in a list in R, you can use the unique function.
In this example,
numbers
with integer values.unique
function to the list to remove duplicates.numbers <- c(1, 2, 2, 3, 4, 4, 5)
unique_numbers <- unique(numbers)
print(unique_numbers)
[1] 1 2 3 4 5
In this example,
words
with string values.unique
function to the list to remove duplicates.words <- c('apple', 'banana', 'cherry', 'apple', 'banana')
unique_words <- unique(words)
print(unique_words)
[1] "apple" "banana" "cherry"
In this tutorial, we learned How to Remove Duplicates in a List in R language with well detailed examples.