在Twitter用户列表中使用表函数

时间:2015-03-25 14:24:30

标签: r twitter table-functions

我正在使用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

我强迫Candidate成为没有成功的矢量。 你有任何想法克服这个问题,或者你知道另一个函数而不是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

0 个答案:

没有答案