rbind dataframes from a list

后端 未结 1 1439
南旧
南旧 2021-01-24 07:42

One of my functions return a list of dataframes which I need to concatenate into 1 single dataframe. I do this using:

 do.call(rbind,list_df)

T

相关标签:
1条回答
  • 2021-01-24 08:36

    From the output of "out_df", it looks like a nested list. We could try

    out <- do.call(rbind, do.call(c, list_df))
    str(out)
    # 'data.frame':   10 obs. of  5 variables:
    # $ v1: int  1 2 3 4 5 1 2 3 4 5
    # $ v2: int  6 7 8 9 10 6 7 8 9 10
    # $ v3: int  11 12 13 14 15 11 12 13 14 15
    # $ v4: int  16 17 18 19 20 16 17 18 19 20
    # $ v5: int  21 22 23 24 25 21 22 23 24 25
    

    data

    list_df <- lapply(1:2, function(i) list(data.frame(v1=1:5, 
           v2= 6:10, v3= 11:15, v4 = 16:20, v5= 21:25)))
    

    Using the OP's code,

    do.call(rbind, list_df)
    #     [,1]  
    #[1,] List,5
    #[2,] List,5
    
    0 讨论(0)
提交回复
热议问题