Combine a list of data frames into one data frame

前端 未结 9 2058
半阙折子戏
半阙折子戏 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 11:58

    Here's another way this can be done (just adding it to the answers because reduce is a very effective functional tool that is often overlooked as a replacement for loops. In this particular case, neither of these are significantly faster than do.call)

    using base R:

    df <- Reduce(rbind, listOfDataFrames)
    

    or, using the tidyverse:

    library(tidyverse) # or, library(dplyr); library(purrr)
    df <- listOfDataFrames %>% reduce(bind_rows)
    

提交回复
热议问题