I am new to R and I'm trying ti convert a list to data frame.

Consider a nested list of data. Length of the list is 145 and each item has a list of length of 30.

Is there any way to convert this structure into a data frame of 145 rows and 30 columns?

```l <- replicate(
145,
list(sample(letters, 30)),
simplify = FALSE
)``` Apr 12, 2018 15,098 views

## 1 answer to this question.

Let's assume your list of lists is called 'a':

`data <- data.frame(matrix(unlist(a), nrow=145, byrow=T))`

The above command will convert all character columns to factors. But, to avoid this add the stringsAsFactors parameters to this call.
Refer below:

`data <- data.frame(matrix(unlist(a), nrow=145, byrow=T),stringsAsFactors=FALSE)`

NOTE: You need to be careful here if all your data is not of same type.
When you pass the data through a matrix, all your data is coerced into a common type.
For Example: If you have one column of character data and one column of numeric data then the numeric data will be coerced to string by matrix() and both to factor by data.frame() answered Apr 12, 2018 by
• 3,120 points

edited Apr 12, 2018 by nirvana

## how to convert a data frame into a list in R

Convert whole data frame into a list?? ...READ MORE

## How to convert tables to a data frame in R ?

> trial.table.df <- as.data.frame(trial.table) //assuming that trial.table ...READ MORE

+1 vote

## How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

## How to filter a data frame with dplyr and tidy evaluation in R?

Requires the use of map_df to run each model, ...READ MORE

+1 vote

## How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

## How to create a list of Data frames?

Basically all we have to do is ...READ MORE

## What is the difference between [] and [[]] notations to access the elements of a list or dataframe in R?

R provides 3 basic indexing operators. Refer ...READ MORE

+1 vote

## How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE