首页 > 解决方案 > 在循环中运行的完全相同的 gtrendsR::gtrends() 调用的结果不一致

问题描述

我遇到了一些奇怪的行为,我不确定是什么原因造成的。在循环中,对过去数据
的相同调用返回不同的结果。 知道可能是什么原因造成的吗?gtrends()

最小的例子:

library(gtrendsR)

unlist(lapply(X = 1:20, function(i) {
  g <- gtrends(
    keyword = c("/m/01k_wh", "/m/03m424"),
    time = "2018-01-01 2018-12-31",
    geo = "GB",
    hl = "en-GB"
  )

  g <- g$interest_over_time

  max(g$hits[g$keyword == "/m/01k_wh"])
}))

# [1] 72 72 72 72 72 72 72 72 72 72 72 72 72 52 52 52 52 52 52 52

会话信息:

R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gtrendsR_1.4.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0       assertthat_0.2.0 crayon_1.3.4     dplyr_0.7.8      R6_2.3.0        
 [6] grid_3.5.2       plyr_1.8.4       gtable_0.2.0     magrittr_1.5     scales_1.0.0    
[11] ggplot2_3.1.0    pillar_1.3.1     rlang_0.3.0.1    lazyeval_0.2.1   rstudioapi_0.8  
[16] bindrcpp_0.2.2   tools_3.5.2      glue_1.3.0       purrr_0.2.5      munsell_0.5.0   
[21] yaml_2.2.0       compiler_3.5.2   pkgconfig_2.0.2  colorspace_1.3-2 tidyselect_0.2.5
[26] bindr_0.1.1      tibble_1.4.2

标签: rgoogle-trendsgtrendsr

解决方案


推荐阅读