Open In App
Related Articles

Convert list to array in R

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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:



Last Updated : 01 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads