Skip to content

Instantly share code, notes, and snippets.

Avatar
🕳️
[ o o ]

Brian Abelson abelsonlive

🕳️
[ o o ]
View GitHub Profile
@abelsonlive
abelsonlive / scrapeBikeShare.R
Created May 13, 2012
Scrape NYC BikeShare Data
View scrapeBikeShare.R
require("rjson")
#generate urls to scrape
#I determined the lowest and highest unique ids
#by looking at the page that had just the coordinates
root.url <- "http://a841-tfpweb.nyc.gov/bikeshare/get_point_info?point="
id<- seq(11992,12404, by=1)
urls <- paste(root.url, id, sep="")
@abelsonlive
abelsonlive / localMorans.R
Created May 17, 2012
Add p-values from Local Moran's test to a shapefile with counts.
View localMorans.R
library("foreign")
library("rgdal")
library("sp")
library("spdep")
library("maptools")
library("SpatialEpi")
library("plyr")
data <- read.dbf("counts.dbf")
shapes <- readShapePoly("counts.shp")
@abelsonlive
abelsonlive / R: New calendarHeat
Created May 17, 2012
R: modify calendarHeat map to allow custom breaks and RColorBrewer functionality
View R: New calendarHeat
require("lattice")
require("makeR")
####################################################################
####################################################################
####################################################################
####################################################################
levelplot.forumula <- function (x, data = NULL, allow.multiple = is.null(groups) ||
outer, outer = TRUE, aspect = "fill", panel = if (useRaster) lattice.getOption("panel.levelplot.raster") else lattice.getOption("panel.levelplot"),
@abelsonlive
abelsonlive / R: unix time to date object
Created May 17, 2012
unix time to date object conversion
View R: unix time to date object
data$date <- as.POSIXlt(data$unix_time, origin="1970-01-01", tz="America/New_York")
data$date <- as.Date(data$date, format="%Y-%m-%d")
@abelsonlive
abelsonlive / merge.csv.R
Created May 27, 2012
merge all csv/xls/etc in a directory by a common field, R
View merge.csv.R
#_______________________________________________________________________________#
#| |#
#| !! keep in mind that each data frame must have only one common field name!! |#
#|_____________________________________________________________________________|#
#create the function for csvs
merge.csv = function(mypath){
filenames=list.files(path=mypath, full.names=TRUE)
datalist = lapply(filenames, function(x){read.csv(file=x,header=T, stringsAsFactors=F)})
@abelsonlive
abelsonlive / genVarNames.R
Created May 27, 2012
Automatically generate variable names from Pattern, R
View genVarNames.R
#// Say you were building a dataset and wanted to automatically
#// generate variable names by some pattern.
#// For instance, you might want to do this with population counts
#// within 100 census tracts by race
#// IE:
#
# tracts <- paste("c", rep(1:100), sep="")
# race - c("black", "white", "hispanic")
#
#// In this case you would want to generate 300 unique variable names
@abelsonlive
abelsonlive / getInsights.R
Created May 27, 2012
getInsights - an R API for Google Insights
View getInsights.R
#see below for query specifications
getInsights <- function(
username = "Insights4R@gmail.com",
password = "googleinsights4r",
text_query = "'hello world'",
date_query = "1/2004 108m",
geo_query = "US",
search_type= "all",
filter_category="none"){
@abelsonlive
abelsonlive / gist:3311043
Created Aug 10, 2012 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts
View gist:3311043

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
View cartodb2R
path_to_file = "~/Desktop/Vizzuality-cartodb-r-05eb537/CartoDB_1.4.tar.gz"
install.packages(path_to_file, repos=NULL, type="source")
require("CartoDB")
account_name = "parks-datadive"
api_key = "[ON THE BOARD IN 517-F]"
cartodb(account_name, api_key)
cartodb.test()
@abelsonlive
abelsonlive / google_geocode.R
Created Sep 9, 2012 — forked from drewconway/google_geocode.R
Grab lat / lon from an address using Google Maps
View google_geocode.R
# Get a lat/lon value for each address
geocode.addr <- function(city, country) {
geo.url <- "http://maps.googleapis.com/maps/api/geocode/json?address="
geo.text <- getURL(paste(geo.url, URLencode(paste(city, country, collapse="+")), "&sensor=false", sep=""))
geo.json <- fromJSON(geo.text)
if(geo.json$status == "OK"){
return(geo.json$results[[1]]$geometry$location)
}
else{
You can’t perform that action at this time.