我目前正在尝试使用R中的for循环将多个90天的时间段合并到一个数据框中。我需要90天的时间段,因为这是Google趋势提供每日趋势数据的唯一方法。到目前为止,这是我所拥有的...但是,当运行时,我得到一个带有0个观测值和0个变量的数据框。 “ dates_ranges”只是我尝试收集趋势数据的90天。
dates_ranges = c(“ 2010-01-01 2010-04-01”,“ 2010-04-01 2010-06-30”,“ 2010-06-30 2010-10-01”,“ 2010-10 -01 2011-01-01“,” 2011-01-01 2011-04-01“,” 2011-04-01 2011-06-30“,” 2011-06-30 2011-10-01“,” 2011 -10-01 2012-01-01“)
gtrendsBPA <-data.frame()
for(i in 1:length(dates_ranges)){ rbind(gtrendsBPA,(gtrends(“ BPA”,geo =“ US”,time = dates_ranges [i])$ interest_over_time))
答案 0 :(得分:0)
您几乎拥有了它,只需要在for循环中将gtrendsBPA
重新分配给它自己,如下所示:
gtrendsBPA = data.frame()
for (i in 1:(length(dates_ranges))) {
gtrendsBPA = rbind(gtrendsBPA, (gtrends("BPA", geo="US", time=dates_ranges[i])$interest_over_time))
}
这应该为您提供所需的结果。