0

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 Answers1

0

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.

  • Okay so this ends up giving me a 0 x 0 matrix, due to the fact that my_messages$messages is NULL. Not used to dealing with lists so not sure how to call objects within lists but it seems like my_messages$messages doesn't work. – Peter Owen Jun 12 '20 at 14:29