0

I have a question about how to append data frame obtaining from the gtrendsR function.

My keywords are each "california" and "texas" and my geographic locations are each "US" and "FR". So, I have 4 trends (california and US, alifornia and FR, texas and US, and texas and FR).

Here is my code.

library(gtrendsR)
state <- c("california", "texas")
nation <- c("US", "FR")

for (i in state) {
  for (j in nation){
    g <- gtrends(keyword = i,geo = j,time ="2020-01-01 2020-01-05",gprop = "web")[[1]]  
    print(g)  
    }
  }

So, I have 4 data frames with for loop. But, I could not append them into one data frame. Please help me solve this problem.

Thanks!

ph7see
  • 57
  • 4

1 Answers1

1

This should work! You should end up with a dataframe called "google_data" which includes all of your output.

library(gtrendsR)
state <- c("california", "texas")
nation <- c("US", "FR")

google_data = data.frame()

for (i in state) {
  for (j in nation){
    g <- gtrends(keyword = i,geo = j,time ="2020-01-01 2020-01-05",gprop = "web")[[1]]  
    output <- data.frame(g)
    google_data <- rbind(google_data,output) 
    }
}

Emily Halford
  • 169
  • 1
  • 7
  • It works for me if time is recent i. e. "2022-01-01 2022-01-05" with the original time I receive this error: Error in interest_over_time(widget, comparison_item, tz) : Status code was not 200. Returned status code:429 – user3591356 Aug 26 '22 at 19:56