Skip to content

Instantly share code, notes, and snippets.

View mdlincoln's full-sized avatar

Matthew Lincoln mdlincoln

View GitHub Profile
@mdlincoln
mdlincoln / row_rep.R
Created November 6, 2015 04:45
dplyr-friendly verb: replicate the rows of a data_frame n times
row_rep <- function(df, n) {
df[rep(1:nrow(df), times = n),]
}
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
# Friends don't let friends use
# two spaces after a period
sed -e 's/\. /. /g'
@mdlincoln
mdlincoln / europop.R
Last active December 18, 2015 14:26
Create an animated GIF of European urban population 1500-1800
library(devtools)
install_github("mdlincoln/europop")
library(europop)
library(dplyr)
library(rgdal)
library(ggplot2)
library(animation)
@mdlincoln
mdlincoln / range_simulation.R
Last active December 18, 2015 16:33
Animated GIF of simulation replications
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 / doc_data.R
Last active March 7, 2016 19:39
Create a skeleton documentation string for an R data.frame
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 / coordinates.csv
Last active April 9, 2016 02:45
Euro population data
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 / project.R
Last active August 10, 2016 01:28
Maintain other attributes when making a bipartite projection
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 %>%

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:

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: