Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用twitteR和dplyr从推特搜索中获取用户的位置_R_Twitter_Dplyr - Fatal编程技术网

使用twitteR和dplyr从推特搜索中获取用户的位置

使用twitteR和dplyr从推特搜索中获取用户的位置,r,twitter,dplyr,R,Twitter,Dplyr,我想使用dplyr从搜索Twitter结果中获取用户的位置 首先,我搜索包含特定标记的tweet,并在dplyr框架中转换它们: tw = searchTwitter('#twitter', n = 100, since = '2012-01-01') tw_df <- tbl_df(map_df(tw, as.data.frame)) 但是,当我想在dplyr管道中组合这些时,我得到了一个错误: tw_df %>% mutate(user.location = locati

我想使用dplyr从搜索Twitter结果中获取用户的位置

首先,我搜索包含特定标记的tweet,并在dplyr框架中转换它们:

tw = searchTwitter('#twitter', n = 100, since = '2012-01-01') 
tw_df <- tbl_df(map_df(tw, as.data.frame))
但是,当我想在dplyr管道中组合这些时,我得到了一个错误:

tw_df %>%
  mutate(user.location = location(getUser(screenName)))
错误:

Error: error in evaluating the argument 'object' in selecting a method for function 'location': Error in twInterfaceObj$doAPICall(paste("users", "show", sep = "/"), params = params,  : 
  Not Found (HTTP 404).
我认为这可能是对twitter多个请求的限制,但是,在dplyr管道之外,它可以工作:

for (i in 1:10) {
    test.user <- getUser("testusername");
    print(location(test.user))
}
for(1:10中的i){
test.user你可以做什么

library(twitteR)
library(dplyr)
tw <- searchTwitter('#twitter', n = 3) 
tw_df <- twListToDF(tw)
tw_df %>%
  rowwise() %>%
  mutate(user.location = twitteR::location(getUser(screenName))) %>%
  select(user.location)
# Source: local data frame [3 x 1]
# Groups: <by row>
# 
# # A tibble: 3 x 1
#                   user.location
#                           <chr>
# 1                              
# 2 En la VI Republica, Venezuela
# 3                 San Mateo, CA
library(twitteR)
图书馆(dplyr)
tw%
mutate(user.location=twitteR::location(getUser(screenName)))%>%
选择(用户位置)
#来源:本地数据帧[3 x 1]
#小组:
# 
##tibble:3 x 1
#用户位置
#                           
# 1                              
#2委内瑞拉共和国第六共和国
#加利福尼亚州圣马特奥3号

tw_df%>%mutate(user.location=location(getUser(screenName))
一次为所有屏幕名提供提要
screenName
。这在这里不起作用。

我使用您的代码随机收到此错误:错误:无法找到签名“NULL”的函数“location”的继承方法'此外:警告消息:在twInterfaceObj$doAPICall中(粘贴(“用户”,“显示”,sep=“/”),params=params,:遇到的速率限制和达到的重试限制-返回部分结果。我有什么做错了吗?似乎你达到了速率限制。使用
lookupUsers
而不是
getUser
,删除
dplyr
并查看处理速率限制的资源。这很奇怪,只要我超过5,我就知道了错误…这是一个相当低的资源限制。如果您“表现良好”并遵守twitter条款,您应该能够在每15分钟的窗口内执行180个请求。但是,正如我所说,/
getUser()
无论如何都不适用于批量查询。
library(twitteR)
library(dplyr)
tw <- searchTwitter('#twitter', n = 3) 
tw_df <- twListToDF(tw)
tw_df %>%
  rowwise() %>%
  mutate(user.location = twitteR::location(getUser(screenName))) %>%
  select(user.location)
# Source: local data frame [3 x 1]
# Groups: <by row>
# 
# # A tibble: 3 x 1
#                   user.location
#                           <chr>
# 1                              
# 2 En la VI Republica, Venezuela
# 3                 San Mateo, CA