Converting List to Vector
Here we are going to convert the R list to vector, for this we will create a list first and then unlist the list into the vector.
R
# Create lists. lst <- list (1:5) print (lst) # Convert the lists to vectors. vec <- unlist (lst) print (vec) |
[[1]] [1] 1 2 3 4 5 [1] 1 2 3 4 5
R – Lists
A list in R programming is a generic object consisting of an ordered collection of objects. Lists are one-dimensional, heterogeneous data structures.
The list can be a list of vectors, a list of matrices, a list of characters, a list of functions, and so on.
A list is a vector but with heterogeneous data elements. A list in R is created with the use of the list() function.
R allows accessing elements of an R list with the use of the index value. In R, the indexing of a list starts with 1 instead of 0.