Skip to content

Instantly share code, notes, and snippets.

Matt Bannert mbannert

Block or report user

Report or block mbannert

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View boar_snippets.R
dpl_gr <- function(ds,vars){
ds %>%
group_by_(.dots = vars) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
}
dpl_gr(mtcars,c("am","cyl"))
View utopia_example.R
library(MASS)
set.seed(123)
m <- mvrnorm(10000, mu = c(20,2.6),
Sigma = matrix(c(8,0.85,0.85,.57),
ncol = 2),
empirical = TRUE)
disp <- m[,1]
wt <- m[,2]
am <- rbinom(10000,1,.4)
View computeScores.R
computeScores <- function(dframe,
maplist,
fct = sum,
na.rm = T){
li <- lapply(maplist,function(x){
out <- dframe[,grep(x,names(dframe),value=T)]
apply(out,1,fct, na.rm = na.rm)
})
View tstools.R
# # convenience package...
# central vs. decentralized production discussion
# not part of this.
# minimal introduction to R
# different editors and an interpreter
# How-to-R Studio
# # 4 Panes
# # the ctrl+1 ctrl+2 shortcut
# # don't store
View scrape_aea_list.R
library(openxlsx)
library(rvest)
journals <- read_html("https://www.aeaweb.org/econlit/journal_list.php")
j <- journals %>%
html_nodes(".journal") %>%
html_text()
dflist <- lapply(j,function(x){
View simple_reg_sweave_texreg.Rnw
\documentclass{article}
\begin{document}
<<regression,results='asis'>>=
library(texreg)
data(mtcars)
fit1 <- lm(mpg~wt+disp,data=mtcars)
texreg(fit1)
@mbannert
mbannert / benchmark.R
Last active Dec 15, 2016
jsonlite vs rjsonion - can we make jsonlite faster?
View benchmark.R
library(microbenchmark)
# json test is a character vector of length 2 containing
# both of the json elements given in sample_data.json
microbenchmark(
lite <- lapply(json_test,function(x){
jsonlite::fromJSON(x,simplifyVector = F)
}),
SONIO <- lapply(json_test,function(x){
@mbannert
mbannert / aws-install.sh
Created Apr 27, 2016
Shiny Server AWS EC2 install script
View aws-install.sh
#!/usr/bin/env bash
# extend resources list and install R
sudo bash -c "echo 'deb http://stat.ethz.ch/CRAN/bin/linux/ubuntu trusty/' >> /etc/apt/sources.list"
sudo apt-get update
sudo apt-get install r-base
# install postgresql
sudo apt-get install postgresql
@mbannert
mbannert / read geo file
Created Apr 21, 2016
PostgreSQL Postgis R GeoJSON example
View read geo file
# Postgis data type in my case is WSG84: geom | geometry(Point,4326)
library(jsonlite)
library(RPostgreSQL)
source("dbConnect.R") # create some connection object called con
p <- dbGetQuery(con,
"SELECT id,
postal_code,
st_asGeoJSON(geom)
FROM sometable
You can’t perform that action at this time.