0

我正在使用 TwitteR 包开发一个小功能。该函数将查看多个 twitter 帐户的关注者,并返回关注者列表及其出现次数。

为此,我使用一个简单的循环来创建一个包含所有关注者的列表:

Targetlist <- c("Username2","Username1",..., "UsernameM")

#initialisation of variable for the loop
Nsearch <- length(Targetlist)
Csearch = 1
Candidate = NULL

#Loop screening all followers and saving them in Candidate
While (Nsearch >= Csearch) {
Target= getUser(Targetlist[Csearch])
followers=Target$getFollowers()
Candidate = c(Candidate, followers)
Csearch= Csearch+1}

运行循环后,我想应用 Table 函数以了解每个关注者出现在候选人中的时间

Candidate_list <- table(Candidate)

问题函数返回我以下错误

Error in unique.default(x, nmax = nmax) : 
  unique() applies only to vectors

我强迫候选人成为向量而没有成功。您有什么想法可以克服这个问题,或者您知道要使用另一个函数来代替 table() 吗?

str(candidate) 返回一个元素列表,如下所示(我只放了其中一个元素):

$ 1073973901:Reference class 'user' [package "twitteR"] with 18 fields
  ..$ description      : chr "Student at #UniKonstanz, blogger at #alwaysbeaturbest"
  ..$ statusesCount    : num 24
  ..$ followersCount   : num 52
  ..$ favoritesCount   : num 46
  ..$ friendsCount     : num 122
  ..$ url              : chr "https://example.com/s1zB30hGrZ"
  ..$ name             : chr "Victoria Ilcheva "
  ..$ created          : POSIXct[1:1], format: "2013-01-09 14:40:54"
  ..$ protected        : logi FALSE
  ..$ verified         : logi FALSE
  ..$ screenName       : chr "VictoriaIlcheva"
  ..$ location         : chr ""
  ..$ lang             : chr "en"
  ..$ id               : chr "1073973901"
  ..$ lastStatus       :Reference class 'status' [package "twitteR"] with 17 fields
  .. ..$ text         : chr "@derekhalpern Hi Derek, just read your eBook, so great to keep your advice in mind when starting a blog! P.S. I LOVE the secret"| __truncated__
  .. ..$ favorited    : logi FALSE
  .. ..$ favoriteCount: num 0
  .. ..$ replyToSN    : chr "derekhalpern"
  .. ..$ created      : POSIXct[1:1], format: "2015-03-13 21:30:48"
  .. ..$ truncated    : logi FALSE
  .. ..$ replyToSID   : chr(0) 
  .. ..$ id           : chr "576495652483530752"
  .. ..$ replyToUID   : chr "15323979"
  .. ..$ statusSource : chr "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>"
  .. ..$ screenName   : chr "Unknown"
  .. ..$ retweetCount : num 0
  .. ..$ isRetweet    : logi FALSE
  .. ..$ retweeted    : logi FALSE
  .. ..$ longitude    : chr(0) 
  .. ..$ latitude     : chr(0) 
  .. ..$ urls         :'data.frame':    0 obs. of  4 variables:
  .. .. ..$ url         : chr(0) 
  .. .. ..$ expanded_url: chr(0) 
  .. .. ..$ dispaly_url : chr(0) 
  .. .. ..$ indices     : num(0) 
  .. ..and 51 methods, of which 39 are possibly relevant:
  .. ..  getCreated, getFavoriteCount, getFavorited, getId, getIsRetweet,
  .. ..  getLatitude, getLongitude, getReplyToSID, getReplyToSN, getReplyToUID,
  .. ..  getRetweetCount, getRetweeted, getRetweeters, getRetweets,
  .. ..  getScreenName, getStatusSource, getText, getTruncated, getUrls,
  .. ..  initialize, setCreated, setFavoriteCount, setFavorited, setId,
  .. ..  setIsRetweet, setLatitude, setLongitude, setReplyToSID, setReplyToSN,
  .. ..  setReplyToUID, setRetweetCount, setRetweeted, setScreenName,
  .. ..  setStatusSource, setText, setTruncated, setUrls, toDataFrame,
  .. ..  toDataFrame#twitterObj
  ..$ listedCount      : num 0
  ..$ followRequestSent: logi FALSE
  ..$ profileImageUrl  : chr "http://pbs.twimg.com/profile_images/567458828758036480/GSVig5yx_normal.jpeg"
  ..and 57 methods, of which 45 are possibly relevant:
  ..  getCreated, getDescription, getFavorites, getFavoritesCount,
  ..  getFavouritesCount, getFollowerIDs, getFollowers, getFollowersCount,
  ..  getFollowRequestSent, getFriendIDs, getFriends, getFriendsCount, getId,
  ..  getLang, getLastStatus, getListedCount, getLocation, getName,
  ..  getProfileImageUrl, getProtected, getScreenName, getStatusesCount,
  ..  getUrl, getVerified, initialize, setCreated, setDescription,
  ..  setFavoritesCount, setFollowersCount, setFollowRequestSent,
  ..  setFriendsCount, setId, setLang, setLastStatus, setListedCount,
  ..  setLocation, setName, setProfileImageUrl, setProtected, setScreenName,
  ..  setStatusesCount, setUrl, setVerified, toDataFrame,
  ..  toDataFrame#twitterObj
4

0 回答 0