1

Is there an easy way to "invert" the organisation of a list from, say

list(c(TRUE, TRUE, FALSE), c(FALSE, FALSE, FALSE))

[[1]]
[1]  TRUE  TRUE FALSE

[[2]]
[1] FALSE FALSE FALSE

to

[[1]]
[1]  TRUE  FALSE

[[2]]
[1] TRUE FALSE

[[3]]
[1] FALSE FALSE

?

I'm working with an lapply command that returns a list organised in a way that's very inconvenient. I didn't manage to turn around the arguments in the lapply command so it produces a list in a way I can further process.

Yozef
  • 113
  • 8
  • 2
    Try: `do.call(Map, c(c, lst))` if `lst` is the name of your list... – Ben Aug 22 '21 at 16:43
  • A write up as answer, with elucidation of `c(c` construct would be appreciated, as it performs exactly as OP desired. – Chris Aug 22 '21 at 16:50
  • If you are happy to use non-`base`: `data.table::transpose`. See e.g. [Fastest way to transpose a list in R / Rcpp](https://stackoverflow.com/questions/30164803/fastest-way-to-transpose-a-list-in-r-rcpp) – Henrik Aug 22 '21 at 17:26
  • Sorry @Chris - I was going to post an answer but see it is closed (and understandably so - there are other answers that do address this already, I agree with Henrik). If there was sufficient interest in a greater explanation and it was reopened, I would be happy to share an answer. (But again, I'm totally fine either way!). – Ben Aug 22 '21 at 18:10

0 Answers0