【问题标题】:Download data from google trends into R with a loop使用循环将数据从谷歌趋势下载到 R 中
【发布时间】:2017-04-23 03:13:52
【问题描述】:

我需要从 Google Trends 下载几个词的搜索量。之后我想将文件保存为 csv。

我尝试了以下方法:

单词

很明显,趋势中的数据被覆盖了,所以在这种情况下,手球只剩下最后一个词了。如何下载多个数据?

感谢您的帮助!

里卡达

【问题讨论】:

    标签: r loops download google-trends gtrendsr


    【解决方案1】:

    你可以这样尝试:

    library(gtrendsR)
    # Switch https://www.google.com/settings/security/lesssecureapps to on if needed:
    gconnect("username", "password")
    words <-c("Tennis","Fußball", "Handball") 
    trends<- gtrends(words, geo="DE",start_date = as.Date("2004-01-01"), end_date = as.Date(Sys.time()))
    for (word in tolower(words)) 
      write.csv( trends$trend[, c("start", "end", word)], paste0(word, ".csv") )
    

    【讨论】:

      【解决方案2】:

      这样做。

      write.csv(yourobject$tableframe, file= "filedir\\filename.csv") 
      

      要获取表格,请执行names(myobject)

      然后你就成功了。

      【讨论】:

      • 请编辑您的答案以包含一些解释。仅代码的答案对教育未来的 SO 读者几乎没有作用。您的答案因质量低劣而在审核队列中。 (请格式化您的代码)
      猜你喜欢
      • 2021-01-17
      • 2021-08-09
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      相关资源
      最近更新 更多