Skip to content

Instantly share code, notes, and snippets.

View jbryer's full-sized avatar

Jason Bryer jbryer

View GitHub Profile
@jbryer
jbryer / BirthdayProblem.R
Created January 31, 2012 20:29
Given a room with n people in it, what is the probability any two will have the same birthday?
## See http://en.wikipedia.org/wiki/Birthday_problem for an explanation of the problem
require(ggplot2)
require(reshape)
theme_update(panel.background=theme_blank(),
panel.grid.major=theme_blank(),
panel.border=theme_blank())
birthday <- function(n) {
1 - exp( - n^2 / (2 * 365) )
@jbryer
jbryer / EmailClass.R
Created January 20, 2012 14:30
Example of object oriented programming in R
#' Constructor
EmailClass <- function(name, email) {
nc = list(
name = name,
email = email,
get = function(x) nc[[x]],
set = function(x, value) nc[[x]] <<- value,
props = list(),
history = list(),
getHistory = function() return(nc$history),
@jbryer
jbryer / RBloggers.R
Created January 13, 2012 15:14
Retrieving and Analyzing R-Bloggers using the Google Reader API
source('https://raw.github.com/gist/1606595/269d61dfcc7930f5275a212e11f3c43771ab2591/GoogleReader.R')
rbloggers = getRSSFeed(feedURL="http://r-bloggers.com/feed",
email="GOOGLE READER EMAIL",
passwd="GOOGLE READER PASSWORD",
posts=5000)
entries = rbloggers[which(names(rbloggers) == "entry")]
length(entries)
saveXML(rbloggers, file='rbloggers.xml')
@jbryer
jbryer / GoogleReader.R
Created January 13, 2012 14:46
Function to return an RSS feed using the (unofficial) Google Reader API
require(XML)
require(RCurl)
#' This function ruturns an XML tree of the RSS feed from the given URL.
#'
#' This function utilizes the (unofficial) Google Reader API to retrieve RSS
#' feeds. The advantage of access RSS feeds through the Google Reader API is that
#' you are not limited by the number of entries a website may included in their
#' feed. That is, Google maintains generally maintains a complete history of
#' entries from the RSS feed.
@jbryer
jbryer / RPackageInstaller.R
Created November 23, 2011 03:11
Install basic set of R packages
.libPaths() #By default, R will install packages to the first element
#This script will install some very common R packages.
repos = 'http://cran.r-project.org' #Main CRAN
repos.win = 'http://www.stats.ox.ac.uk/pub/RWin' #Site provides some prebuilt binaries for Windows
repos.rforge = 'http://r-forge.r-project.org'
libraries = c('Deducer', 'devtools', 'doBy', 'foreign', 'gdata', 'ggplot2', 'gmaps',
'Hmisc', 'JGR', 'maps', 'mapdata', 'mapproj', 'maptools', 'proto', 'psych', 'R2wd',
'Rcmdr', 'RCurl', 'reshape', 'RODBC', 'roxygen2', 'seqinr', 'sm', 'sp',