In R, you can copy a list using the list() function or the list slice syntax.
In this example,
original_list
using the list() function with some elements.copied_list
.copied_list
contains all elements of original_list
.original_list <- list(a = 1, b = 2, c = 3)
copied_list <- list(original_list)
print(original_list)
print(copied_list)
List of 3 $ a: num 1 $ b: num 2 $ c: num 3 List of 1 $ :List of 3 ..$ a: num 1 ..$ b: num 2 ..$ c: num 3
In this example,
original_list
with some elements.[[]]
to create a copy named copied_list
.copied_list
contains all elements of original_list
.original_list <- list(a = 1, b = 2, c = 3)
copied_list <- original_list[[]]
print(original_list)
print(copied_list)
List of 3 $ a: num 1 $ b: num 2 $ c: num 3 List of 3 $ a: num 1 $ b: num 2 $ c: num 3
In this tutorial, we learned How to Copy a List in R language with well detailed examples.