Combine a list of data frames into one data frame

前端 未结 9 2158
半阙折子戏
半阙折子戏 2020-11-21 11:25

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 ques

9条回答
  •  春和景丽
    2020-11-21 12:07

    The only thing that the solutions with data.table are missing is the identifier column to know from which dataframe in the list the data is coming from.

    Something like this:

    df_id <- data.table::rbindlist(listOfDataFrames, idcol = TRUE)
    

    The idcol parameter adds a column (.id) identifying the origin of the dataframe contained in the list. The result would look to something like this:

    .id a         b           c
    1   u   -0.05315128 -1.31975849 
    1   b   -1.00404849 1.15257952  
    1   y   1.17478229  -0.91043925 
    1   q   -1.65488899 0.05846295  
    1   c   -1.43730524 0.95245909  
    1   b   0.56434313  0.93813197  
    

提交回复
热议问题