我想每小时通过包“gtrendsR”提取谷歌趋势数据,我尝试使用 Sys.sleep() 函数设置计时器,但是每小时下载一次对我来说是失败的。那么,我如何更正我的代码以便每小时获取数据。非常感谢!
Sys.setlocale("LC_ALL", "English")
Keywords = c("google", "twitter")
for (k in Keywords) {
res = NULL
temp_1 <- gtrends(k, geo = "US",time = "all")
temp_2 <- temp_1$interest_over_time
res <- rbind(res, temp_2)
rm(temp_1,temp_2)
res <- select (res, c(date, hits))
Sys.setlocale(category = "LC_ALL", locale = "cht")
names(res)[2]<- k
xfilepath = paste("C:/Users/Peter/Desktop/",k,".csv",sep="")
write.csv(res, file = xfilepath, row.names=FALSE)
}