I’ve used loops to iterate over data by #, my first line in the loop code is:

for (i in seq(from=x1, to=xp, by=5)) {

where x1 is the column you want to start with, xp is the column you want to end with, and “by=5” is the iteration I think you are trying to achieve

 

Tricia Kyzar

Ph: 352-392-7260

Email: [log in to unmask]

 

From: UF R Users List <[log in to unmask]> On Behalf Of Morton,Bailey A
Sent: Wednesday, December 5, 2018 1:48 PM
To: [log in to unmask]
Subject: Re: Google Trends Issues

 

 

Good Afternoon All, 

 

Sorry to inquire about this topic again, but I was wondering if anyone had any experience with loops to assist in iterating over the country codes.

 

Best,

Bailey Morton 


On Dec 4, 2018, at 3:59 PM, Morton,Bailey A <[log in to unmask]> wrote:


Good Afternoon Geraldine, 

 

Thank you again for pointing out my error with the country codes. I haven’t worked in loops in a while, so I was wondering if you had any suggestions as to how to iterate by 5 over the country codes. 

 

Please let me know! 

 

Best,

Bailey Morton 


On Dec 3, 2018, at 9:33 AM, Klarenberg,Geraldine <[log in to unmask]> wrote:

Hi Bailey

 

If you load the “countries” data as per the error message, and do "unique(countries$country_code)”, you get a list of all the country codes - and AC is not in it:

 

[1] AF   AL   DZ   AS   AD   AO   AI   AQ   AG   AR   AM   AW   AU   AT   AZ   BS   BH   BD   BB   BY  

 [21] BE   BZ   BJ   BM   BT   BO   BA   BW   BV   BR   IO   BN   BG   BF   BI   KH   CM   CA   CV   KY  

 [41] CF   TD   CL   CN   CX   CC   CO   KM   CG   CD   CK   CR   CI   HR   CU   CY   CZ   DK   DJ   DM  

 [61] DO   TP   EC   EG   SV   GQ   ER   EE   ET   FK   FO   FJ   FI   FR   GF   PF   TF   GA   GM   GE  

 [81] DE   GH   GI   GB   GR   GL   GD   GP   GU   GT   GN   GW   GY   HT   HM   VA   HN   HK   HU   IS  

[101] IN   ID   IR   IQ   IE   IL   IT   JM   JP   JO   KZ   KE   KI   KP   KR   KW   KG   LA   LV   LB  

[121] LS   LR   LY   LI   LT   LU   MO   MK   MG   MW   MY   MV   ML   MT   MH   MQ   MR   MU   YT   MX  

[141] FM   MD   MC   MN   MS   MA   MZ   MM   NR   NP   NL   AN   NC   NZ   NI   NE   NG   NU   NF   MP  

[161] NO   OM   PK   PW   PA   PG   PY   PE   PH   PN   PL   PT   PR   QA   RE   RO   RU   RW   SH   KN  

[181] LC   PM   VC   WS   SM   ST   SA   SN   SC   SL   SG   SK   SI   SB   SO   ZA   GS   ES   LK   SD  

[201] SR   SJ   SZ   SE   CH   SY   TW   TJ   TZ   TH   TG   TK   TO   TT   TN   TR   TM   TC   TV   UG  

[221] UA   AE   US   UY   UZ   VU   VE   VN   VG   VI   WF   EH   YE   YU   ZM   ZW   BQ   ME   <NA> PS  

[241] RS   SS   TL   UM   AX   BL   CW   GG   IM   JE   MF   SX   XZ

252 Levels: AD AE AF AG AI AL AM AN AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO ... ZW

 

And as for making it efficient, you could use a loop (or a pipe) to iterate over the list of country names by 5 (as 5 is the maximum number of search terms you can include).

 

Kind regards

Geraldine

 



On Dec 3, 2018, at 8:11 AM, Morton,Bailey A <[log in to unmask]> wrote:

 


Good Morning All, 



I have been having some issues trying to download data from the google trends index database. I am trying to download searches for “FIFA”, for all the available years and countries to measure the popularity of soccer in the past 12-14 years. 



I ran the code below using the appropriate Google country codes but I have been unable to download the data. 



> library(gtrendsR)

> fifa_trends <- gtrends(keyword = "FIFA" , geo= c("AC" , "AD" , "AE" ,  "AF" ,  "AG" ,"AI", "AL", "AM", "AN" ,"AO", "AQ", "AR", "AS" ,"AT" ,"AU", "AW" , "AZ" ,  "BA" ,  "BB" ,  "BD" , "BE", "BF", "BG", "BH", "BI", "BJ", "BM", "BN", "BO" ,"BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "FX", "GA", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR" ,"KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV" ,"MW", "MX", "MY", "MZ", "NC" ,"NE", "NF" ,"NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE","PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TM", "TN", "TO" ,"TP", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UK", "UM", "US", "UY", "UZ", "VA", "VC", "VE" ,"VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZR", "ZW") , time = "all")

Error in gtrends(keyword = "FIFA", geo = c("AC", "AD", "AE", "AF", "AG",  : 

  length(geo) <= 5 is not TRUE

 

> library(gtrendsR)

> fifa_trends <- gtrends(keyword = "FIFA" , geo= c("AC" , "AD" , "AE" ,  "AF" ,  "AG") , time = "all")

Error: Country code not valid. Please use 'data(countries)' to retreive valid codes.

 

 

 

If anyone happens to be familiar with using the gtrendsR package or has a more efficient way to access this data, please let me know.



Best,

Bailey Morton

 

Sent from my iPhone

This list strives to be beginner friendly. However, we still ask that you PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

 

This list strives to be beginner friendly. However, we still ask that you PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

This list strives to be beginner friendly. However, we still ask that you PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

This list strives to be beginner friendly. However, we still ask that you PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.