How do I split a column with lists in all its rows?

My dataframe has thousands of rows of data. Reprex-

rownum   adgroup
1        list(abc=123,efg=456)
2        Null
3        list(abc=457, efg= 666)

I want my final output to drop 'adgroup', split the column elements and add 2 columns. the df should look like

rownum  abc  efg
1       123  456
2       Null Null
3       457  666

I tried

Reprex$ad_group[c(1)]
[[1]]
NULL

But that just gave 1 value. Why doesnt it show all thousands of rows of data

I also tried
reprex$ad_group[sapply(string, function(x) any(x == "abc"))]
Error in lapply(X = X, FUN = FUN, ...) : object 'string' not found

Hi, I think tidyr::unnest_wider() could be of help here: Rectangle a nested list into a tidy tibble — hoist • tidyr

Read through but really didnt follow how i could apply to my issue. Please advise

Try tidyr::unnest_wider(df, adgroup)

1 Like

worked. thanks for the suggestion

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.