How to Convert a Vector to a List in R Programming (Example Code)
In this article you’ll learn how to convert a vector object to a list in the R programming language.
Construction of Example Data
example_vector <- 1:10 # Creating example data |
example_vector <- 1:10 # Creating example data
Example: Convert Vector to List with the as.list() Function
example_list <- as.list(example_vector) # Application of as.list() function example_list # Printing result # [[1]] # [1] 1 # # [[2]] # [1] 2 # # [[3]] # [1] 3 # # [[4]] # [1] 4 # # [[5]] # [1] 5 # # [[6]] # [1] 6 # # [[7]] # [1] 7 # # [[8]] # [1] 8 # # [[9]] # [1] 9 # # [[10]] # [1] 10 |
example_list <- as.list(example_vector) # Application of as.list() function example_list # Printing result # [[1]] # [1] 1 # # [[2]] # [1] 2 # # [[3]] # [1] 3 # # [[4]] # [1] 4 # # [[5]] # [1] 5 # # [[6]] # [1] 6 # # [[7]] # [1] 7 # # [[8]] # [1] 8 # # [[9]] # [1] 9 # # [[10]] # [1] 10