1
library(gtrendsR)
user <- "@gmail.com"
psw <- "password"
gconnect(user, psw) 
lang_trend <- gtrends(c("Soccer", "Footbal" , "Basketball"), res="7d")
plot(lang_trend)

enter image description here

I would like to produce similar resalts with a loop over the list:

sport<- as.list(c("Soccer", "Footbal" , "Basketball"))


mylist= list() #create a empty list
for (i in sport) {
  dat <- gtrends(sport[1], res="7d")
  dat$i <- i  # Here I would like to add the name of the sports
  datalist[[i]] <- gtrends(a[1], res="7d") # add it to your list
}

I would like to produce a table/data frame like that:

Date    Soccer     Football   Basketball
12.06     100        50           30
13.06      90        30           20
14.06      80        40           20
Googme
  • 914
  • 7
  • 27
  • Your code doesn't make any sense. What is `a`? What is `datalist`? They weren't defined anywhere. Also, why `as.list(c(...` instead of just `c`? Also, why are you running `gtrends` twice in your loop? – David Arenburg Jun 19 '16 at 16:45
  • It is also unclear what are you trying to do in general. Would something like this work for you (on your `lang_trend` data)? `library(data.table) ; setDT(lang_trend$trend)[, lapply(.SD, sum), by = .(Date = as.IDate(start))]` – David Arenburg Jun 19 '16 at 17:03
  • @DavidArenburg thank you very much for that. It was excactly what I was looking for. I just not understand the `Date` and `end` columns. Would you like to post a solution in order for me to confirm it? – Googme Jun 19 '16 at 17:12

0 Answers0