Skip to content

Instantly share code, notes, and snippets.

View sebastianbarfort's full-sized avatar

Sebastian Barfort sebastianbarfort

View GitHub Profile
@kogakure
kogakure / .gitignore
Last active November 19, 2024 13:22
Git: .gitignore file for LaTeX projects
*.acn
*.acr
*.alg
*.aux
*.bak
*.bbl
*.bcf
*.blg
*.brf
*.bst
@rbochet
rbochet / .gitignore
Created March 16, 2011 03:48 — forked from kogakure/.gitignore
.gitignore file for LaTeX projects on Mac
# Latex files
*.aux
*.glo
*.idx
*.log
*.toc
*.ist
*.acn
*.acr
@benmarwick
benmarwick / citation-analysis-sketch.R
Last active December 14, 2021 15:23
sketch of citation analysis
# sources:
# http://www.jgoodwin.net/?p=1223
# http://orgtheory.wordpress.com/2012/05/16/the-fragile-network-of-econ-soc-readings/
# http://nealcaren.web.unc.edu/a-sociology-citation-network/
# http://kieranhealy.org/blog/archives/2014/11/15/top-ten-by-decade/
# http://www.jgoodwin.net/lit-cites.png
###########################################################################
# This first section scrapes content from the Web of Science webpage. It takes
@dmarcelinobr
dmarcelinobr / looping_files.R
Created January 2, 2014 22:00
This piece loops text files, read them, merge them, and write back a file.
path = "~/Documents/My Data/BRAZIL/Elections/"
out.file<-""
file.names <- dir(path, pattern =".txt")
for(i in 1:length(file.names)){
file <- read.table(file.names[i],header=TRUE, sep=";", stringsAsFactors=FALSE)
out.file <- rbind(out.file, file)
}
write.table(out.file, file = "cand_Brazil.txt",sep=";",
row.names = FALSE, qmethod = "double",fileEncoding="windows-1252")
# This script uses httr to download data from Google's API
# Notice ther is a limit of 2,500 calls per day
library(httr)
base_url <- "http://maps.google.com/maps/api/geocode/json"
geoCode <- function(address,verbose=FALSE) {
r <- GET(base_url, query = list(address = address, sensor = "false"))
stop_for_status(r)
@skranz
skranz / s_dplyr
Created March 21, 2014 07:48
Wrappers to dplyr's data modification functions like arrange, select,... that work with string arguments.
# Helper functions that allow string arguments for dplyr's data modification functions like arrange, select etc.
# Author: Sebastian Kranz
# Examples are below
#' Modified version of dplyr's filter that uses string arguments
#' @export
s_filter = function(.data, ...) {
eval.string.dplyr(.data,"filter", ...)
}
library(httr)
library(XML)
library(selectr)
xpath <- function(x) structure(x, class = "xpath")
sel <- function(x) xpath(css_to_xpath(x, prefix = "//"))
url <- "http://www.boxofficemojo.com/movies/?id=ateam.htm"
html <- content(GET(url), "parsed")
@christophergandrud
christophergandrud / R_Jags_AmazonEc2_Setup.sh
Last active October 28, 2017 20:26
Demonstration script for setting up R, Git, and Jags on Ubuntu instance of Amazon EC2 Server
# Set up RStudio and JAGS on an Amazon EC2 instance
# Using Ubuntu 64-bit
# Partially from http://blog.yhathq.com/posts/r-in-the-cloud-part-1.html
# See yhat for EC2 instance set up
# Navigate to key pair
# ssh -i YOUR_KEYPAIR.pem ubuntu@PUBLIC_DNS
# Add a user/password.
# This will become your RStudio username and password.
@zmjones
zmjones / partial_dependence_party.R
Last active August 29, 2015 14:04
parallel calculation of marginal or joint dependence of explanatory variables from a party random forest
pkgs <- c("party", "parallel")
invisible(lapply(pkgs, require, character.only = TRUE))
partial_dependence <- function(fit, ivar, cores = 1, ...) {
## calculates the partial dependence of the response on explanatory variable(s)
## fit must be a party object
## ivar must be a character vector of length >= 1 all of which
## exist in the dataframe used to fit the model
## if the length of ivar > 1, joint dependence is calculated
df <- data.frame(get("input", fit@data@env), get("response", fit@data@env))
@timelyportfolio
timelyportfolio / code.R
Last active August 29, 2015 14:11
density plot with rCharts
library(ggplot2)
library(pipeR)
library(rCharts)
#using ggplot2 stat_density help example
library(plyr) # to access round_any
movies$decade <- round_any(movies$year, 10)