我一直在使用一个函数来获取具有帐户名称的数据框的所有twitter关注者。然后,我开始在较小的数据框(5个测试帐户)中使用该功能,效果很好。但是,当我使用该函数和整个数据框(大约150个帐户)时,会出现错误消息。
#for this function (get_followers) we need a handmade solution with a for-loop
#data frame
profiles <- df2$Account
#function
getAllFollowers <- function (name) {
user_info <- lookup_users(name)
user_follower <- get_followers(name, n=user_info$followers_count, retryonratelimit = TRUE)
Sys.sleep(2) #sleep for 2 seconds
return(user_follower) }
#return a list with all follower-ID's per politician (adjusting X is relevant)
list_1 <- lapply(X = profiles, FUN = getAllFollowers)
预期结果是每个帐户及其关注者的列表。不幸的是,有一条错误消息:
Error in `[[<-.data.frame`(`*tmp*`, i, value = list(url = list(urls = list( :
replacement has 2 rows, data has 1