In this tutorial, we will learn how to convert a matrix to a dataframe in R programming.

To convert Matrix to Dataframe in R, use as.data.frame() function. The syntax of as.data.frame() function is

You can also provide row names to the dataframe using row.names.

Example to Convert Matrix to Dataframe in R

In this example, we will take a simple scenario wherein we create a matrix and convert the matrix to a dataframe.

You might be quizzed that the Dataframe looks like the transposed version of the Matrix. But, it is totally fine. It is just that these two data objects: matrix and dataframe are represented differently.

Example to Convert Matrix to Dataframe with Column Names

In this example, we create a matrix, and convert this matrix to a dataframe with row names.

Concluding this R Tutorial, we have learned to convert a matrix to a dataframe, with the help of examples.