x <- 1:5
y <- letters[1:3]
z <- matrix(1:4, nrow = 2)
# Create named list from objects
my_list <- list2(x, y, z)
names(my_list) # "x" "y" "z"
# Works with explicit names too
my_list2 <- list2(a = x, b = y)
names(my_list2) # "a" "b"
Run the code above in your browser using DataLab