Skip to content
Fix Code Error

Convert a list to a data frame

March 13, 2021 by Code Error
Posted By: Anonymous

I have a nested list of data. Its length is 132 and each item is a list of length 20. Is there a quick way to convert this structure into a data frame that has 132 rows and 20 columns of data?

Here is some sample data to work with:

l <- replicate(
  132,
  as.list(sample(letters, 20)),
  simplify = FALSE
)

Solution

Update July 2020:

The default for the parameter stringsAsFactors is now default.stringsAsFactors() which in turn yields FALSE as its default.


Assuming your list of lists is called l:

df <- data.frame(matrix(unlist(l), nrow=length(l), byrow=TRUE))

The above will convert all character columns to factors, to avoid this you can add a parameter to the data.frame() call:

df <- data.frame(matrix(unlist(l), nrow=132, byrow=TRUE),stringsAsFactors=FALSE)
Answered By: Anonymous

Related Articles

  • Combining items using XSLT Transform
  • Pandas: Get Grouped and Conditioned Last Value
  • How do I vectorize a Pandas function that counts…
  • How do I record if a value has been previously seen…
  • Generate new observations based on IF statement R
  • How to convert Hour: minutes: seconds to decimal number in R
  • late event seems not being dropped when doing…
  • Sequential occurrence (advanced gaps and islands problem)
  • How can I turn the unique values of a column into…
  • Linear transformation and matrix multiplication…
  • How to convert time format in numeric in R
  • Centering in CSS Grid
  • How do I include certain conditions in SQL Count
  • Grouping functions (tapply, by, aggregate) and the…
  • Dodged bar plot in R based on to columns with count…
  • Convert array to nested JSON object - Angular Material tree
  • How to find the overall top played game name by each…
  • Subtract three rows from an array in angular 7
  • SQL Query : Add values to columns based on other columns
  • Can I access results of "setup_data" from…
  • How to do, each row grouping and get previous date's…
  • How to retain value and compute based on group of…
  • How do I manipulate a Dataframe with Pivot_Table in Python
  • Using Excel to GROUP BY and find date WHERE MAX
  • How to add 'load more' functionality to items on a…
  • Pandas: Looking back in time
  • Rolling Average Home and Away
  • "Large data" workflows using pandas
  • How to Correctly Use Lists in R?
  • Partition a Dataset according to the Min & Max…
  • Plotting curve over several subplots in R
  • SQL query return data from multiple tables
  • Right way to convert data.frame to a numeric matrix,…
  • Joining and comparing values of one df with first…
  • R replace multiple variables in a string using a…
  • How to make a great R reproducible example
  • First week of year considering the first day last year
  • How can I view the source code for a function?
  • How to get the date a status changes in a time series?
  • Playing with a Pandas Dataframe with Time Column
  • how to print greatest sum each rows in python?
  • How to plot a wide dataframe with colors and…
  • Ordering dates in R with lubridate
  • Display Grid does not work in Polymer correctly
  • Running a cron every 30 seconds
  • How to select a foreign key after narrowing down via…
  • Conditional aggregation based on groups in a data frame R
  • Matching identical columns
  • How to generate a random string of a fixed length in Go?
  • missing observations when replicating sample()
  • How to edit `cell[i]` in data grid view C# win form…
  • Multiple dates rows to turn in 2 columns in a df…
  • Tips for Aggregating MongoDB Time Trend Data over…
  • Android Image View Pinch Zooming
  • Split a list from Dataframe column into specific column name
  • data.table vs dplyr: can one do something well the…
  • DirectX and DirectXTK translation limits
  • How to automate parameters passed into pandas.read_sql?
  • In R, prevent unlist from removing NULL values, by…
  • Solutions to a system of inequalities in R
  • Getting the mode of a character column after every…
  • Efficient way of transforming a ddiMatrix to Bigmatrix in R
  • How do I convert a column from "unknown" to date in…
  • How do you dynamically allocate a matrix?
  • How to show title in hover - css / jquery
  • Find the top 30% of the industry's revenue in the…
  • Running a loop on multiple .txt files in one folder in R
  • How to pass 2D array (matrix) in a function in C?
  • Attaching a row of numbers/ a vector to an existing…
  • Error: Cannot find module 'polka' on Heroku
  • For loop for writing an excel file using xlsx?
  • How to combine the data from two different…
  • So there is CM_satisfaction coulmn that contains…
  • Javascript and SVG - move element with offset
  • R - Unique values from days under x days from given…
  • symbolic complex expression simplification
  • Maximum occurrence in sequence (advanced gaps and…
  • R function to plot inequalities with shading
  • Python dataframe subtract datetime for each unique…
  • percentage value for monthly data with pandas
  • How to make partition by some range of values in…
  • Peak signal detection in realtime timeseries data
  • What to change in circular barplot in R?
  • How create new col by increment it based on MIN(DATE) in SQL
  • Fastest way to pad a dataframe with uneven columns
  • How to make vuetify navigation drawer to close group…
  • Statistical Calculus In Big Data Set Wrong Values
  • How can I access and process nested objects, arrays or JSON?
  • Random meetings in large graphs: efficient way of…
  • Create Bullet Graph using ggplot2 or plotly in R
  • Create variable for day of the experiment
  • Chrome / Safari not filling 100% height of flex parent
  • how to deploy successfully React app with nextjs to…
  • Real mouse position in canvas
  • I need to sum values with specific condition
  • Add new row to dataframe, at specific row-index, not…
  • Valid values for android:fontFamily and what they map to?
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • create more than once 2d array in python
  • ternary operator usage within v-bind class

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Getting a list of all subdirectories in the current directory

Next Post:

Pushing to Git returning Error Code 403 fatal: HTTP request failed

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error