Reputation: 1
I need to download the search volume from Google Trends for several words. Afterwards I'd like to save the files as csv.
I tried the following:
words <-c("Tennis","Fußball", "Handball") for ( i in 1:length(words) ){ trends <- gtrends(words[i], geo="DE",start_date = as.Date("2004-01-01"), end_date = as.Date(Sys.time()))$trend write.csv(trends, file="trends.csv") }
Obviously the data in trends gets overwritten, so that just the last word in this case Handball remains. How do I download several data?
Thank you for your help!
Ricarda
Upvotes: 0
Views: 1387
Reputation: 1
do this.
write.csv(yourobject$tableframe, file= "filedir\\filename.csv")
to get tables do names(myobject)
then you nailed it.
Upvotes: 0
Reputation: 54237
You could try it like this:
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") )
Upvotes: 1