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
print(paste("step", i)) | |
print(paste(i/n*100, "%")) |
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
find: ([a-z]) (["])([a-z]) | |
replace: $1 \\$2$3 | |
find: ."" | |
replace: ./"" | |
find: ([a-z])(["]) ([a-z]) | |
replace: $1\\$2 $3 |
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.packages("foreign") | |
library("foreign") | |
data = read.dbf("path/to/file.dbf") | |
write.csv(data, "path/to/file.csv", row.names=F) |
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
# fill area under a line: | |
plot(x,y, type="n) | |
lines(x,y) | |
polygon( c(min(x), x, max(x)), c( min(y), y, min(y)), density=100 ) |
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
geocode.addr <- function(uid_query) { | |
require("rjson") | |
require("RCurl") | |
require("plyr") | |
uid <- uid_query$uid | |
query <- uid_query$query | |
geo.url <- "http://maps.googleapis.com/maps/api/geocode/json?address=" | |
geo.text <- try(getURL(paste(geo.url, URLencode(query), "&sensor=false", sep=""))) |
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
# best practices for web scraping in R # | |
# function should be used with ldply | |
# eg: | |
ldply(urls, scrape) | |
# add a try to ignore broken links/ unresponsive pages | |
# eg: |
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
#/bin/bash | |
# run chmod +x THIS_GIST.sh | |
# configure for debian or ubuntu! debian has dependencies that ubuntu's libs will conflict with | |
# sources: | |
# http://cran.r-project.org/bin/linux/debian/ | |
# http://cran.r-project.org/bin/linux/ubuntu/README | |
# http://stackoverflow.com/questions/10255082/installing-r-from-cran-ubuntu-repository-no-public-key-error | |
clear |
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
# helper function: get number of words in a string, separated by tab, space, return, or point. | |
nwords <- function(x){ | |
res <- strsplit(as.character(x), "[ \t\n,\\.]+") | |
res <- lapply(res, length) | |
unlist(res) | |
} | |
# sanitize file name for terminal usage (i.e., escape spaces) | |
sanitize <- function(str) { | |
gsub('([#$%&~_\\^\\\\{}\\s\\(\\)])', '\\\\\\1', str, perl = TRUE) |
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
require("RColorBrewer") | |
# not run: | |
# model = lm(y~x1+x2+x3+x4...) | |
# Construct quantile table for varialbes of interest | |
# t value: n-p=df.residual=634, alpha=5%,50%. t(1-alpha/2, n-p) | |
t.05 <- qt(1-0.025, 634, lower.tail = TRUE, log.p=FALSE) | |
t.5 <- qt(1-0.25, 634, lower.tail = TRUE, log.p=FALSE) | |
coef.quantil <- data.frame(matrix(0, nrow=length(model$coefficients)-1, ncol=8)) |
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
# Drawing a scatter plot of raster images | |
doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
toInstall <- c("png", "devtools", "MASS", "RCurl") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Some helper functions, lineFinder and makeTable | |
source_gist("818983") | |
source_gist("818986") |