使用rtweet/igraph从twitter用户ID确定用户是否是彼此的朋友

使用rtweet/igraph从twitter用户ID确定用户是否是彼此的朋友,r,twitter,igraph,rtweet,R,Twitter,Igraph,Rtweet,我使用twitter数据进行机器学习,在试图查找用户之间的关系时,我被R中的rtweet包中的查找友谊所困扰。 实际上,我有一个用户ID列表,如:- frnd_20$user_id <chr> 818910970567344128 52544275 39344374 41634520 22203756 39349894

我使用twitter数据进行机器学习,在试图查找用户之间的关系时,我被R中的rtweet包中的查找友谊所困扰。 实际上,我有一个用户ID列表,如:-

frnd_20$user_id
<chr>
818910970567344128              
52544275                
39344374                
41634520                
22203756                
39349894                
50769180                
22703645                
471672239               
23970102
frnd\u 20$user\u id
818910970567344128
52544275
39344374
41634520
22203756
39349894
50769180
22703645
471672239
23970102
是否有任何方法可以确定上述用户是否是彼此的朋友。我试着使用get_friendships(),但它给出了一个大约2000行的数据帧,通过它们查找友谊非常耗时

    df <- c()
for ( i in 1:20) {
  source_frnd <- frnd_20$screen_name[i]
  for(j in 1:20){
    target_frnd <- frnd_20$screen_name[j]
    a<-lookup_friendships(source_frnd,target_frnd)
    df <- rbind(df,a)
  }

}

df此答案查看您当前的数据集,并检查用户之间是否存在任何关系以及他们的追随者(在
rtweet
软件包术语中的友谊)。没有找到。您可能希望与一些您知道相关的用户进行检查

# reading in the data provided
a <- "
818910970567344128              
52544275                
39344374                
41634520                
22203756                
39349894                
50769180                
22703645                
471672239               
23970102 "

df <- read.table(text = a, header = FALSE)
names(df) <- "targ_users"
df$targ_users <- as.character(df$targ_users)

# getting followed accounts with the rtweet function `get_friends`
frnds <- get_friends(users = df$targ_users)

library(dplyr)
frnds %>% group_by(user) %>% summarise(n = n())
# A tibble: 10 x 2
   user                   n
   <chr>              <int>
 1 22203756              40
 2 22703645              97
 3 23970102              76
 4 39344374            1463
 5 39349894             926
 6 41634520               4
 7 471672239            832
 8 50769180             343
 9 52544275            1448
10 818910970567344128    15

frnds %>% group_by(user) %>% filter(user %in% user_id)
# A tibble: 0 x 2
# Groups:   user [0]
# ... with 2 variables: user <chr>, user_id <chr>
这确认了原始答案-集合中没有用户跟随其他用户

# make data frame of just the users
u_df <- as.data.frame(unique(frnds$user)) 

# make data frame of all the followed users
f_df <- as.data.frame(unique(frnds$user_id))

# check if any common id's are in the two groups
u_df %in% f_df
[1] FALSE