In R, sets are typically represented using vectors. To copy a set, you can simply assign it to a new variable.
In this example,
numbers
containing some integer elements.numbers
to a new variable named copiedNumbers
.copiedNumbers
contains a copy of all elements from numbers
.numbers <- c(1, 2, 3, 4, 5)
copiedNumbers <- numbers
print("Copied Numbers:")
print(copiedNumbers)
Copied Numbers: [1] 1 2 3 4 5
In this example,
fruits
containing some string elements.fruits
to a new variable named copiedFruits
.copiedFruits
contains a copy of all elements from fruits
.fruits <- c("Apple", "Banana", "Cherry", "Date")
copiedFruits <- fruits
print("Copied Fruits:")
print(copiedFruits)
Copied Fruits: [1] "Apple" "Banana" "Cherry" "Date"
In this tutorial, we learned How to Copy a Set in R language with well detailed examples.