我正在尝试从RefClass中提取数据,我正在尝试将其转换为数据帧。有人可以解释如何做到这一点?解释为什么有人会使用RefClass而不是数据帧也很棒。
s <- searchTwitter('#United')
str(s[1])
getRefClass("status")
#console output
> str(s[1])
List of 1
$ :Reference class 'status' [package "twitteR"] with 17 fields
..$ text : chr "#Waterbury #united #earringswag #twitteraddict Import #and #profit. #the complete guide to importing goods: How T http://t.co/D"| __truncated__
..$ favorited : logi FALSE
..$ favoriteCount: num 0
..$ replyToSN : chr(0)
..$ created : POSIXct[1:1], format: "2015-09-13 05:11:48"
..$ truncated : logi FALSE
..$ replyToSID : chr(0)
..$ id : chr "642928643795058688"
..$ replyToUID : chr(0)
..$ statusSource : chr "<a href=\"http://twitterfeed.com\" rel=\"nofollow\">twitterfeed</a>"
..$ screenName : chr "ArielKaylee1"
..$ retweetCount : num 0
..$ isRetweet : logi FALSE
..$ retweeted : logi FALSE
..$ longitude : chr(0)
..$ latitude : chr(0)
..$ urls :'data.frame': 1 obs. of 5 variables:
.. ..$ url : chr "http://t.co/D2kr0RzecR"
.. ..$ expanded_url: chr "http://bit.ly/1UM4xF0"
.. ..$ display_url : chr "bit.ly/1UM4xF0"
.. ..$ start_index : num 114
.. ..$ stop_index : num 136
..and 53 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
>
答案 0 :(得分:0)
我最终通过使用:
找到答案> df<-NULL
> df <- sapply(s, function(x) x$toDataFrame())