Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Lincoln mdlincoln

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am mdlincoln on github.
  • I am mdlincoln (https://keybase.io/mdlincoln) on keybase.
  • I have a public key whose fingerprint is 5271 D84C 193A 4B9B 945C D4AA D3AB 2911 2CAD 6E14

To claim this, I am signing this object:

@mdlincoln
mdlincoln / project.R
Last active Aug 10, 2016
Maintain other attributes when making a bipartite projection
View project.R
library(igraph)
library(dplyr)
# Assume you have a dataframe "objects" with columns "object_id", "artist_id", "date"
# Create an identical table that just gives a new variable name to "artist_id"
flipped_objects <- objects %>% rename(artist_id = artist2_id)
# Join the tables together (essentially joining objects to itself, creating every combination
# of artist that share an object_id and date
edges <- objects %>%
@mdlincoln
mdlincoln / coordinates.csv
Last active Apr 9, 2016
Euro population data
View coordinates.csv
city coordinates
'S HERTOGENBOSCH 51.69917,5.30417
AACHEN 50.77664,6.08342
AALST 50.93604,4.0355
ABBEVILLE 50.1,1.83333
ABERDEEN 57.14369,-2.09814
ACIREALE 37.60666,15.16279
AGEN 44.2,0.63333
AIX EN PROVENCE 43.5283,5.44973
ALBI 43.9298,2.148
@mdlincoln
mdlincoln / doc_data.R
Last active Mar 7, 2016
Create a skeleton documentation string for an R data.frame
View doc_data.R
doc_data <- function(d) {
# Get column names and types
vartype <- vapply(d, typeof, FUN.VALUE = character(1))
# Write individual item description templates
items <- paste0("#\' \\item{\\code{", names(vartype), "}}{", vartype, ". ###}", collapse = "\n")
# Return the full documentation template
paste0("#\' DATASET TITLE
#\'
@mdlincoln
mdlincoln / range_simulation.R
Last active Dec 18, 2015
Animated GIF of simulation replications
View range_simulation.R
library(ggplot2)
library(dplyr)
library(animation)
load(url("http://matthewlincoln.net/assets/docs/sim_data.rda"))
saveGIF({
# We want one frame per replication
for(i in 1:max(bm_raw_sims$r)) {
@mdlincoln
mdlincoln / europop.R
Last active Dec 18, 2015
Create an animated GIF of European urban population 1500-1800
View europop.R
library(devtools)
install_github("mdlincoln/europop")
library(europop)
library(dplyr)
library(rgdal)
library(ggplot2)
library(animation)
View spaces.sh
# Friends don't let friends use
# two spaces after a period
sed -e 's/\. /. /g'
View gist:f2b660851b14f3a455f9
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
@mdlincoln
mdlincoln / row_rep.R
Created Nov 6, 2015
dplyr-friendly verb: replicate the rows of a data_frame n times
View row_rep.R
row_rep <- function(df, n) {
df[rep(1:nrow(df), times = n),]
}
@mdlincoln
mdlincoln / mogrify.sh
Last active Nov 4, 2015
imageMagick convert any image to 300x300 DPI
View mogrify.sh
convert image -density 300 -units pixelsperinch outimage