Flatten list and push list key to vector on second level

后端 未结 2 1287
自闭症患者
自闭症患者 2021-01-28 13:21

I suppose this is simple, but I just can\'t seem to figure it out. I need to flatten the second level structure and push the list name/key to a vector on the same level as the

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-28 13:36

    Edit: To get to the list format you indicate above in base R, use rbind to build the data frame, then unlist the necessary elements with lapply.

    With your list above, you can use do.call to call rbind in base R:

    example<-data.frame(ID = as.character(names(myList)), do.call("rbind", myList), row.names = NULL)
    exAsList <-lapply(example, function(x) x <- unlist(x, use.names = FALSE))
    exAsList
    

提交回复
热议问题