in r combine a list of lists into one list

前端 未结 2 554
温柔的废话
温柔的废话 2020-12-06 17:55

I cannot find out can to get a list of all entry of the sublists? Here\'s a simple example, a list o lists:

listoflists <- list(\"A\"=list(c(1,2,3),c(2,34         


        
2条回答
  •  余生分开走
    2020-12-06 18:51

    We can use the concatenate function (c) within do.call to flatten the nested list

    res <- do.call(c, listoflists)
    all.equal(listofvectors, res, check.attributes = FALSE)
    #[1] TRUE
    

    Or as @d.b mentioned in the comments, unlist with recursive = FALSE can also work

    unlist(listoflists, recursive = FALSE)
    

提交回复
热议问题