如何将 for 循环的输出数据帧嵌套在 R 中的现有数据帧中
我有一个关于美国国会议员的数据框,我正在使用 gtrendsR 包从谷歌趋势收集更多数据。鉴于谷歌趋势不允许我在单个查询中搜索所有国会成员,我决定创建一个 ForLoop,一次收集一位政客的数据。
for (i in df$name_google){
user <- i
res <- gtrends(c(obama, user), geo = c("US"), time = "all")
}
然而,谷歌趋势输出文件(res
)本身就是一个包含许多数据帧的列表。
我想使用for循环将此列表保存到df
中的新列,循环的每次迭代都会将新的res文件添加到行中刚刚搜索到的用户。我不知道该怎么做,但就像我添加到下面的循环中的行一样。如果我未能提供必要的信息,请告诉我。
for (i in df$name_google){
user <- i
res <- gtrends(c(obama, user), geo = c("US"), time = "all")
#df$newlistvariable <- res if df$name == i
}
I have a dataframe on members of the US congress and I'm am collecting additional data from google trends using the gtrendsR package. Given that google trends won't allow me to search all members of congress in a single query, I've decided to create a ForLoop that collects the data for one politician at a time.
for (i in df$name_google){
user <- i
res <- gtrends(c(obama, user), geo = c("US"), time = "all")
}
However, the google trends output file (res
) is itself a list with a number of dataframes.
I would like to use the for loop to save this list to a new column in df
, with each iteration of the loop adding the new res file to the row the of the user it just searched. I don't know how to do this, but something like the line i added to the lop below. Let me know if I'm failing to include necessary info.
for (i in df$name_google){
user <- i
res <- gtrends(c(obama, user), geo = c("US"), time = "all")
#df$newlistvariable <- res if df$name == i
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论