Combine a list of data frames into one data frame

前端 未结 9 2162
半阙折子戏
半阙折子戏 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:10

    An updated visual for those wanting to compare some of the recent answers (I wanted to compare the purrr to dplyr solution). Basically I combined answers from @TheVTM and @rmf.

    Code:

    library(microbenchmark)
    library(data.table)
    library(tidyverse)
    
    dflist <- vector(length=10,mode="list")
    for(i in 1:100)
    {
      dflist[[i]] <- data.frame(a=runif(n=260),b=runif(n=260),
                                c=rep(LETTERS,10),d=rep(LETTERS,10))
    }
    
    
    mb <- microbenchmark(
      dplyr::bind_rows(dflist),
      data.table::rbindlist(dflist),
      purrr::map_df(dflist, bind_rows),
      do.call("rbind",dflist),
      times=500)
    
    ggplot2::autoplot(mb)
    

    Session Info:

    sessionInfo()
    R version 3.4.1 (2017-06-30)
    Platform: x86_64-w64-mingw32/x64 (64-bit)
    Running under: Windows 7 x64 (build 7601) Service Pack 1
    

    Package Versions:

    > packageVersion("tidyverse")
    [1] ‘1.1.1’
    > packageVersion("data.table")
    [1] ‘1.10.0’
    

提交回复
热议问题