in Education by
I have code that at one place ends up with a list of data frames which I really want to convert to a single big data frame. I got some pointers from an earlier question which was trying to do something similar but more complex. Here's an example of what I am starting with (this is grossly simplified for illustration): listOfDataFrames <- vector(mode = "list", length = 100) for (i in 1:100) { listOfDataFrames[[i]] <- data.frame(a=sample(letters, 500, rep=T), b=rnorm(500), c=rnorm(500)) } I am currently using this: df <- do.call("rbind", listOfDataFrames) Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
To combine several data frames into one data frame, you can use the bind_rows() function from the dplyr package that adds the unique row names based on the names of list elements. In your case: bind_rows(list_of_dataframes, .id = "column_label") For example: df1 <- mtcars[1:4, ] df2 <- mtcars[11:14, ] bind_rows(df1, df2) Output: mpg cyl disp hp drat wt qsec vs am gear carb 1 21.0 Six 160.0 110 3.90 2.620 16.46 0 1 4 4 2 21.0 Six 160.0 110 3.90 2.875 17.02 0 1 4 4 3 22.8 Four 108.0 93 3.85 2.320 18.61 1 1 4 1 4 21.4 Six 258.0 110 3.08 3.215 19.44 1 0 3 1 5 17.8 Six 167.6 123 3.92 3.440 18.90 1 0 4 4 6 16.4 Eight 275.8 180 3.07 4.070 17.40 0 0 3 3 7 17.3 Eight 275.8 180 3.07 3.730 17.60 0 0 3 3 8 15.2 Eight 275.8 180 3.07 3.780 18.00 0 0 3 3 You can read more about it here.

Related questions

0 votes
    I have a data frame called "newprice" (see below) and I want to change the column names in my program in R. > newprice ... 164 In fact, this is what am doing: names(newprice)[1]...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I have a data frame with a column of p-values and I want to make a selection on these p-values. > pvalues_anova ... 7.125751e-01 5.193604e-01 4.835312e-04 Selection way: anovatest...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Let's say that I have a date in R and it's formatted as follows. date 2012-02-01 2012-02-01 2012-02- ... generate the day by the date. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me a quick way to convert a nested list of data whose length is 100 and each item is a list of ... 100 rows and 10 columns? I am attaching a sample data: 5...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    I want to bind two data frames with different set of columns and I also want to retain all the columns that fails to ... do that in R? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Here are two data frames : df1 = data.frame(CId = a(1:6), Item = b(rep("TV", 3), rep("Book", 3 ... I do a SQL style select statement Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    I want a way to create a empty data.frame in R, I just want to point out data types for each column and name it without any row created. df...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I have a dataframe: > myvec name order_no 1 Nehal 12 2 sejal 14 3 sejal 16 4 shyam 11 5 Nehal 12 6 Sejal 16 ... Sejal 3 Shyam 1 Ram 1 Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I want to remove some questions from data frame, I know how to delete them individually using df$x...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Want to remove the lines from data frame from that : Have NAs across all columns a b c d e f 1 YASH00000206234 0 ... 0 1 2 3 2 Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    import pandas as pd from itertools import combinations, product, permutations MH_P= ["Maria Herrera"] OP_P= ["Oscar ... i solve it? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    When I convert a factor to a numeric or integer, I get the underlying level codes, not the values as numbers. f...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I wish to divide pandas dataframe to 3 separate sets. I know by using train_test_split from sklearn.cross_validation, ... ? kindly help Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have a list and I want to remove a single element from it. How can I do this? I've tried looking ... 't found anything appropriate. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    There are two different methods for accessing the element of a list or data frame- [ ] and [[ ]] , ... the difference between them? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
...