Skip to content
Related Articles

Related Articles

Convert list to array in R

Improve Article
Save Article
  • Last Updated : 01 Sep, 2021
Improve Article
Save Article

A list can be converted to array in R by calling unlist( ) function with created list as parameter. Now pass the unlist() function into array() function as parameter, and use dim attribute for specifying number of rows, columns and matrices. unlist() converts list to vector.

 Syntax : 

array( unlist( list_variable ) , dim = ( rows ,columns , matrices ))

Given below are various implementation for the same:

Example 1 :

R




lst1=list(1:10)
 
arr=array(unlist(lst1),dim=c(3,3,3))
print(arr)

Output :

Example 2 :

R




lst1=list(c("karthik","nikhil","sravan"))
 
arr=array(unlist(lst1),dim=c(1,3,3))
print(arr)

Output:

Example 3 :

R




lst1=list(c("karthik","chandu","nandu"))
 
arr=array(unlist(lst1),dim=c(1,3,2))
print(arr)

Output:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!