R: How to save lists into csv?

前端 未结 3 1148
野趣味
野趣味 2020-12-05 12:01

So im actually working on twitteR and i need a way to store my tweets into a csv file and pull it out when i need it . This is due to the idea i want to compile the tweets i

相关标签:
3条回答
  • 2020-12-05 12:25

    Not tested, but from what I've read online, it seems like the following should work:

    1. Convert the list to a data.frame

      library(plyr) 
      tweets.df = ldply(tweets, function(t) t$toDataFrame())
      
    2. Use write.csv as before, but just on the tweets.df object instead of the tweets object.

      write.csv(tweets.df, file = "newfile.csv")
      

    Sources: Here and here. See also: ?"status-class".

    0 讨论(0)
  • 2020-12-05 12:41

    You can use the following to convert tweets into tweets dataframe:

    tweets.df <- do.call("rbind", lapply(tweets, as.data.frame)) 
    

    Then use tweets.df in your write.csv function.

    0 讨论(0)
  • 2020-12-05 12:43

    using twitteR package:

    convert your tweets to data frame

    tweets2df <- twListToDF(tweets)
    

    then save it to csv

    write.csv(tweets2df, file = "tweets.csv")
    
    0 讨论(0)
提交回复
热议问题