help with google trends

Please I need help with creating a percentage difference graph from a google trend group of keywords data set.

library(gtrendsR)
kwd.symb=c("fever", "cough", "chills", "headache",
       "sneezing", "tiredness", "lost of smell", "lost of taste",
       "sore throat", "running nose", "shortness of breath", "nausea", "diarrhea","fatigue", "body aches") 
n_symb=length(kwd.symb)

# 1.delta dominated period
us.symb1=symb_time1=avg.hits.symb1=vector(mode="list", length = length(kwd.symb)) # create empty list objs 
#avg.hits.symb1=NULL
dput(for ( i in 1:n_symb){
us.symb1[[i]]=gtrends(keyword=kwd.symb[i], time="2021-10-01 2021-10-31", geo = "US") 
symb_time1[[i]]=us.symb1[[i]]$interest_over_time # now interest_time is a data frame
avg.hits.symb1[i]=mean(symb_time1[[i]]$hits)})
#> Error in start_top:end_top: NA/NaN argument

Created on 2022-07-12 by the reprex package (v2.0.1)

Please I need assistance with this ,
thank you

I think you need to explain what you are trying to do in general substantive terms.

Then, more specifically why you are creating the three lists: us.symb1, symb_time1, avg.hits.symb1

Thank you for your response.
I needed to create a loop for google trends search on symptoms of covid , so that is the loop named us.symb 1. From the trend search I took out the data frame called interest over time and named it symb_time1 and found the mean of the coulumn hits from the symb_time 1 data.frame and called that avg.hits.symb1. But I keep on getting errors when I run them.

I needed to create a loop for google trends search on symptoms of covid , so that is the loop named us.symb 1

Why? Serious question, it is often easier and better not to use loops in R if it can be avoided. Can you supply us with a link to the google data or, perhaps better yet, a sample of the data you are working with? A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need.

I needed to create a loop for google trends search on symptoms of covid , so that is the loop named us.symb 1.

As far as I am aware you cannot name a loop in R

What this is doing is setting up three empty lists, each with 15 sub-lists into which you can pack whatever you want.

For example

xx  <- 1:5
symb_time1[[1]]  <- xx

stores an integer vector in *symb_time1[[1]] *

Have a look at loops.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.