R – Convert Vector to List
In this tutorial, we will learn how to convert a vector into a list in R programming Language.
To convert a vector into a list in R, use as.list(
) function.
The syntax of as.list()
function that takes a vector x
and returns a list is
</>
Copy
as.list(x)
Example
In this example, we take a vector in x
, and convert it to a list.
Example.R
</>
Copy
x = c("A", "B", "C", "D", "E")
print(x)
output = as.list(x)
print(output)
Output
> print(x)
[1] "A" "B" "C" "D" "E"
> print( output )
[[1]]
[1] "A"
[[2]]
[1] "B"
[[3]]
[1] "C"
[[4]]
[1] "D"
[[5]]
[1] "E"
Conclusion
In this R Tutorial, we learned how to convert a vector into a list using as.list()
function, with the help of example programs.