Skip to content

Instantly share code, notes, and snippets.

View sebastianbarfort's full-sized avatar

Sebastian Barfort sebastianbarfort

View GitHub Profile
@DenisIzmaylov
DenisIzmaylov / INSTALLATION.md
Last active April 27, 2023 15:44
OS X 10.11 El Capitan: fresh install with Node.js (io.js) Developer Environment

OS X 10.11 (El Capitan) / Node.js and io.js Developer Environment

Custom recipe to get OS X 10.11 El Capitan running from scratch with useful applications and Node.js Developer environment. I use this gist to keep track of the important software and steps required to have a functioning system after fresh install.

Content

@abresler
abresler / tufte
Last active July 4, 2023 18:56
Recreating Edward Tufte's New York City Weather Visualization
library(dplyr)
library(tidyr)
library(magrittr)
library(ggplot2)
"http://academic.udayton.edu/kissock/http/Weather/gsod95-current/NYNEWYOR.txt" %>%
read.table() %>% data.frame %>% tbl_df -> data
names(data) <- c("month", "day", "year", "temp")
data %>%
group_by(year, month) %>%
@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)
@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))
@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.
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")
@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", ...)
}
# 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)
@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")
@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