Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How to extract elements from nested list in R

$
0
0

I'm working with json data which I've converted into a tibble with some list columns. I'm trying to extract the useful information from the list columns but am facing issues. If given the following dataset-

mydf <-tibble( 
  x = c(1, 2, 3),
  y = list(list(list(id="id1", title="title1"), list(id="id11", title="title11")), 
           list(id="id2",title="title2"), 
           NULL)
)

How can I convert it into the following-

data.frame(x=c(1:3), id = c("id1;id11", "id2", ""), title = c("title1;title11", "title2", ""))

#  x       id          title
#1 1 id1;id11 title1;title11
#2 2      id2         title2
#3 3                        

Any help is appreciated. Thanks!


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>