What is the most efficient way to cast a list as a data frame?

前端 未结 7 865
悲&欢浪女
悲&欢浪女 2020-11-29 16:55

Very often I want to convert a list wherein each index has identical element types to a data frame. For example, I may have a list:

> my.list
[[1]]
[[1]]         


        
7条回答
  •  再見小時候
    2020-11-29 17:18

    I can't tell you this is the "most efficient" in terms of memory or speed, but it's pretty efficient in terms of coding:

    my.df <- do.call("rbind", lapply(my.list, data.frame))
    

    the lapply() step with data.frame() turns each list item into a single row data frame which then acts nice with rbind()

提交回复
热议问题