Skip to main content

Introduction to Data Science Version 3

Chapter 13 String Theory

Prior chapters focused on statistical analysis of tweet arrival times and built on earlier knowledge of samples and distributions. This chapter switches gears to focus on manipulating so-called "unstructured" data, which in most cases means natural language texts. Tweets are again a useful source of data for this because tweets are mainly a short (140 characters or less) character strings.

Sources.

R Code for TweetFrame() Function
# TweetFrame() - Return a dataframe based on a search of Twitter
TweetFrame<-function(searchTerm, maxTweets)
{
tweetList <- searchTwitter(searchTerm, n=maxTweets)
# as.data.frame() coerces each list element into a row
# lapply() applies this to all of the elements in twtList
# rbind() takes all of the rows and puts them together
# do.call() gives rbind() all rows as individual elements
tweetDF<- do.call("rbind", lapply(tweetList,as.data.frame))
# This last step sorts the tweets in arrival order
return(tweetDF[order(as.integer(tweetDF$created)), ])
}