Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R – list to dataframe in certain format?

I have data structured like this (but with c. 1000 or so items):

x <- list("test1" = c("a","b","c"),
          "test2" = c("x","y"))

> x
$test1
[1] "a" "b" "c"

$test2
[1] "x" "y"

I’d like to structure it like this:

     l1 l2
1 test1  a
2 test1  b
3 test1  c
4 test2  x
5 test2  y

Ideally in a fairly fast/efficient way as my actual list is quite large

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use

x <- list("test1" = c("a","b","c"),
          "test2" = c("x","y"))

stack(x)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading