Convert List of Multiple Vectors to Single Vector in R (Example Code)

In this tutorial you’ll learn how to transform several vectors in a list to a single vector in the R programming language.

Creation of Exemplifying Data

example_list <- list(LETTERS[1:3],    # Constructing example list in R
                     letters[10:5],
                     "XYX",
                     c("A", "a", "A", "a"))
example_list                          # Displaying example list in RStudio console
# [[1]]
# [1] "A" "B" "C"
# 
# [[2]]
# [1] "j" "i" "h" "g" "f" "e"
# 
# [[3]]
# [1] "XYX"
# 
# [[4]]
# [1] "A" "a" "A" "a"

Example: Unlist List of Vectors

unlist(example_list)                  # Converting list to vector
#  [1] "A"   "B"   "C"   "j"   "i"   "h"   "g"   "f"   "e"   "XYX" "A"   "a"  
# [13] "A"   "a"

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top