How can you convert a data frame column filled with nested list to text strings but keep the the list element names?
I’ve tried:
data_frame$column_new <- paste(unlist(data_frame$column), collapse = “”)
It works but creates a string for each list in corresponding row that doesn’t retain the list element names, it’s almost there.
The list looks like:
data_frame
10000 obs. of 1 variable
column: list of 10000
..$ :list of 1
.. ..$ list of 6
.. .. ..$ apple : chr "small"
.. .. ..$ pear : int 3
.. .. ..$ orange: list()
.. .. ..$ grape: list of 2
next row ..$ :list of 1 .. ..$ list of 6 .. .. ..$ apple : chr "small" .. .. ..$ pear : int 3 .. .. ..$ orange: list() .. .. ..$ grape: list of 2
I want the result put back into the data frame cell:
So currently it looks like this:
data_frame$column
list
list
“”
To....
data_frame$column new_column_string
list new text string of every thing in list (with names kept)
list new text string of list “”
Almost there with his now,
With
<- sapply(data_frame$colum_string,
function(x) paste(unlist(x, use.names = TRUE), collapse = “ “))
But does not keep the list element names!!