rbind a list of data.frames while keeping NULL elements in R

前端 未结 1 1993
南旧
南旧 2021-01-25 09:38

I would like to rbind a list of data.frame and transform NULL elements into NA using R. Consider the following example,

相关标签:
1条回答
  • 2021-01-25 10:16

    Start with transforming the NULL elements:

    l <- lapply(l, function(x) if(is.null(x)) data.frame(C1 = NA) else x)
    
    dplyr::bind_rows(l)
    #  C1 C2
    #1  1  2
    #2 NA NA
    #3  3 NA
    
    0 讨论(0)
提交回复
热议问题