Top Facebook Posts During the US Presidential Debate

October 22, 2012
By

(This article was first published on NERD PROJECT » R project posts, and kindly contributed to R-bloggers)

The following data was collected during the Presidential Debate on the 22nd of October by tapping into the Facebook social graph API using R.

The top three posted links during the debate for each candidate are:

Obama-

#1     http://bit.ly/QCODJg

#2     http://bit.ly/RXstnm

#3    http://bit.ly/P8MmJ1

Romney-

#1    http://bit.ly/zDdsKf

#2    http://bit.ly/SjFbKx

#3    http://bit.ly/SjJaXv

The top five video (for both candidates) of the debate are:

#1    http://bit.ly/WearzC

#2    http://bit.ly/QTEibe

#3    http://bit.ly/VT9xXE

#4    http://bit.ly/SeIGDJ

#5   http://bit.ly/PcKJV5

The top five shared photos are:

#1    http://on.fb.me/TOTPIY

#2    http://on.fb.me/RYF7m6

#3    http://on.fb.me/QCQLkj

#4    http://on.fb.me/RSkXXv

#5    http://on.fb.me/T7Lr6h

This data was collected by tapping into the facebook API using the following R code (adapted from cloudstat.org) run in a loop :

library(RCurl)
library(RJSONIO)

Result fb.base<-paste("http://graph.facebook.com/search?q=",Facebook,"&limit=10",sep="")
fb.url<-getURL(fb.base)
fb.parse<-fromJSON(fb.url)
return(fb.parse)

}

FBdebate<-function(x){
candidate<-list("Romney","Obama")
for(a in candidate){
fbkeyword fbresult fbdata fbdata.length fbid = facebookers = fbmessage = fbpic = fblink = fbname = fbcaption =
fbdescription = fbicon = fbtype = fbcreated = fbupdated = fblikecount = 0
for (i in 1:fbdata.length){
fbid[i] facebookers[i] fbmessage[i] fbpic[i] fblink[i] fbname[i] fbcaption[i] fbdescription[i] fbicon[i] fbtype[i] fbcreated[i] fbupdated[i]fblikecount[i]

#for(j in 1:fblikecount[i]){ fblikename[i] }
assign(paste0("fbtable.", a),as.data.frame(cbind(fbid, facebookers, fbmessage, fbpic, fblink, fbname, fbcaption, fbdescription, fbicon, fbtype, fbcreated, fbupdated, fblikecount, candidate=a)))
}
debate<-merge(fbtable.Romney,fbtable.Obama, all=TRUE)
debate$fbupdated<-format(as.POSIXct(strptime(as.character(debate$fbupdated), "%Y-%m-%dT%H:%M:%S+0000"), tz="GMT"), tz="America/New_York",usetz=TRUE)
debate$fbcreated<-format(as.POSIXct(strptime(as.character(debate$fbcreated), "%Y-%m-%dT%H:%M:%S+0000"), tz="GMT"), tz="America/New_York",usetz=TRUE)
return(debate)
}


To leave a comment for the author, please follow the link and comment on his blog: NERD PROJECT » R project posts.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.