Created
January 18, 2013 06:28
-
-
Save abecode/4562764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install and load additional packages | |
install.packages("zoo") | |
install.packages("chron") | |
library(zoo) | |
library(chron) | |
# read in data | |
dt <- read.delim("movieReports/20130109_to_20120113.tsv",header=TRUE,sep="\t",comment.char="",quote="",na.strings="",fileEncoding="UTF-8") | |
# convert the tweet column from a factor (default) to a character string | |
dt$tweet<-as.character(dt$tweet) | |
# add a dummy variable for counts | |
dt<-transform(dt, dummy=1) | |
# create a zoo object (after many unsuccessful tries) | |
z <- zoo(dt$dummy,order.by=as.chron(as.character(dt$postedTime),format="%Y-%m-%dT%H:%M:%OSZ",tz="GMT")) | |
# aggregate by passing a function that uses another R time functionality | |
aggregate(z,function(x) as.POSIXct(trunc(x,"hour")) ) | |
# plot the time series (by default this will open a popup window | |
plot(aggregate(z,function(x) as.POSIXct(trunc(x,"hour")) )) | |
# this will change the times to Pacific time, from GMT (perhaps there is a better way) | |
plot(aggregate(z,function(x) as.POSIXct(trunc(x-(8/24),"hour")) )) | |
#this will save the | |
# I was interested in a spike that I saw at 2013-01-13 19:00:00: | |
spike<-dt[as.POSIXct(trunc(time(z),"hour"))==as.POSIXct("2013-01-13 19:00:00"),] | |
# this sorts the tweets from the spike by retweet count | |
spike[with(spike,order(retweetCount)),1] | |
# output of top retweetedTweets: | |
# [23340] "RT @goldenglobes: Best Actress in a Motion Picture - Drama - Jessica Chastain - Zero Dark Thirty - #GoldenGlobes" | |
#[23341] "RT @vuecinemas: Help stop the mob with #GangsterSquad on Jan 10th! To win one of 5 movie packs, follow us and retweet this message by 5p ..." | |
# [23342] "Woot! RT @Bad_Wobot1013: Awesome Jessica Chastain!! " | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment