Hussain Shehadeh Hussain Shehadeh - 1 month ago 8
R Question

Appending data in R using get_followers function

I have a list of users in a dataframe. I am trying to find the followers of these users and place them in a single dataframe file. Here is my code:

library(rtweet)

#Searching users with a specific tweet.
A <- search_tweets("RT @ReggaeMarleyBob: Sometimes you have no", n=1000)

#Extract the first column
B <- as.data.frame(A[1], drop=FALSE)

# Drop any duplicate user names:
C <- unique(B)

#collecting the followers of users in C
for(i in 1:nrow(C)) {
print(C[i,1])
D <- get_followers(C[i,1], n= "all", page = "-1", parse = TRUE, as_double = FALSE, token = NULL)
}


Is there a way where I can append the data in C to D?

Answer Source

get_followers returns a data.frame. You can append to a data frame using rbind:

D <- c()
for(i in 1:nrow(C)) {
  print(C[i,1])
  D <- rbind(D, get_followers(C[i,1], n= "all", page = "-1", parse = TRUE, as_double = FALSE, token = NULL))
}