You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
as() performs a type coercion: in other words it changes one type to another type.
lapply() applies a function onto all of the elements of a list.
In the command below, lapply(tweetList, as.data.frame), applies the as.data.frame() coercion to each element in tweetList.
the rbind() function “binds” together the elements that are supplied to it into a row-by-row structure.
the do.call() function executes a function call, but unlike just running the function from the console, allows for a variable number of arguments to be supplied to the function.
The whole command we will use looks like this:
tweetDF <- do.call("rbind", lapply(tweetList, + as.data.frame))
as.data.frame() coerces each list element into a row
lapply() applies this to all of the elements in tweetList
rbind() takes all of the rows and puts them together
do.call() gives rbind() all the rows as individual elements
This takes a list of 500 tweet items (tweetList) and makes it a rectangular data frame. Each of the 500 tweet items had 10 fields, so now we can treat it as 500 observations of 10 variables.
Calling rbind this way sends the 500 results of lapply() to rbind to make one data frame instead of making each tweet into a list.
TweetFrame() - Return a dataframe based on a # search of Twitter
as() performs a type coercion: in other words it changes one type to another type.
lapply() applies a function onto all of the elements of a list.
In the command below, lapply(tweetList, as.data.frame), applies the as.data.frame() coercion to each element in tweetList.
the rbind() function “binds” together the elements that are supplied to it into a row-by-row structure.
the do.call() function executes a function call, but unlike just running the function from the console, allows for a variable number of arguments to be supplied to the function.
The whole command we will use looks like this:
tweetDF <- do.call("rbind", lapply(tweetList, + as.data.frame))
as.data.frame() coerces each list element into a row
lapply() applies this to all of the elements in tweetList
rbind() takes all of the rows and puts them together
do.call() gives rbind() all the rows as individual elements
This takes a list of 500 tweet items (tweetList) and makes it a rectangular data frame. Each of the 500 tweet items had 10 fields, so now we can treat it as 500 observations of 10 variables.
Calling rbind this way sends the 500 results of lapply() to rbind to make one data frame instead of making each tweet into a list.
TweetFrame<-function(searchTerm, maxTweets)
{
twtList<-searchTwitter(searchTerm,n=maxTweets)
return(do.call("rbind",+ lapply(twtList,as.data.frame)))
}
The text was updated successfully, but these errors were encountered: