Convert matrix to list in R Last Updated : 03 May, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to convert a given matrix to a List in R Programming Language. Conversion of a matrix into a list in Column-major order The as.list() is an inbuilt function that takes an R language object as an argument and converts the object into a list. We have used this function to convert our matrix to a list. These objects can be Vectors, Matrices, Factors, and data frames. By default, as.list() converts the matrix to a list of lists in column-major order. Therefore, we have to use unlist() function to convert the list of lists to a single list. unlist() function in R Language is used to convert a list of lists to a single list, by preserving all the components. Syntax: unlist(as.list(matrix)) Example: R mat = matrix(1:12,nrow=3, ncol=4) print("Sample matrix:") print(mat) print("Matrix into a single list") unlist(as.list(mat)) Output: [1] "Sample matrix:" [,1] [,2] [,3] [,4] [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12 [1] "Matrix into a single list" [1] 1 2 3 4 5 6 7 8 9 10 11 12 The time complexity is O(n), where n is the total number of elements in the matrix. The auxiliary space is also O(n), Conversion of a matrix into a list in Row-major order For this approach we first have to find the transpose of the matrix In the code below, we have used t() function to calculate the transpose of our sample matrix. Due to which our matrix gets converted to a list in a Row-Major order. The rest of the process is the same as above. Syntax: unlist( as.list( t(mat) )) Example: R mat = matrix(1:12,nrow=3, ncol=4) print("Sample matrix:") print(mat) print("Result after conversion") unlist(as.list(t(mat))) Output: [1] "Sample matrix:" [,1] [,2] [,3] [,4] [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12 [1] "Result after conversion" [1] 1 4 7 10 2 5 8 11 3 6 9 12 Comment More infoAdvertise with us Next Article Convert dataframe to nested list in R S sudhanshublaze Follow Improve Article Tags : R Language R-Matrix R-List R Matrix-Programs R List-Programs +1 More Similar Reads Convert list to array in R 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 1 min read Convert a given matrix to 1D array in R In this article, let's discuss how to convert a Matrix to a 1D array in R. Functions Usedmatrix() function in R is used to create a matrix Syntax: matrix(data,nrow,ncol,byrow,dimnames) Parameter: data-is the input vector which becomes the data elements of the matrixnrow-is the numbers of rows to be 2 min read Convert dataframe to nested list in R In R Programming Data frame is nothing but a two-dimensional entity that consists of rows and columns whereas Lists in R are data structures that are able to store multiple data values at once. List Creation Lists in R can be created using list() function. Syntax: list(element1, element2, element3,. 2 min read How to Convert a List to a Dataframe in R We have a list of values and if we want to Convert a List to a Dataframe within it, we can use a as.data.frame. it Convert a List to a Dataframe for each value. A DataFrame is a two-dimensional tabular data structure that can store different types of data. Various functions and packages, such as dat 4 min read How to Convert a List to a Dataframe in R We have a list of values and if we want to Convert a List to a Dataframe within it, we can use a as.data.frame. it Convert a List to a Dataframe for each value. A DataFrame is a two-dimensional tabular data structure that can store different types of data. Various functions and packages, such as dat 4 min read How to create a list in R In this article, we will discuss What is a list and various methods to create a list using R Programming Language. What is a list?A list is the one-dimensional heterogeneous data i.e., which stores the data of various types such as integers, float, strings, logical values, and characters. These list 2 min read Like