Created a list in R using gmailr, it looks like a table but I can't convert it to a dataframe

71 Views Asked by At

I have a list that when I print in the console looks like a dataframe. I want to be able to convert this list to a dataframe (with 7 rows and 2 columns) but I am not sure how to. When I unlist this object it just starts to get even messier.

library('gmailr')
my_messages <- gm_messages(serch ="a",num_results =7)
length(my_messages)
my_messages
glimpse(my_messages)

How do I create a 7x2 dataframe that looks exactly like it does in the console from a list that's structured like it is currently?

enter image description here

1

There are 1 best solutions below

1
On

Have you tried calling

t(data.frame(lapply(my_messages$messages, unlist)))

The idea is to apply unlist an each row/message, then to convert it to a dataframe and finally to transpose the whole dataframe. Let me know, if this helps.