Skip to content

Instantly share code, notes, and snippets.

View abresler's full-sized avatar

Alex Bresler abresler

View GitHub Profile
@abresler
abresler / README.md
Created March 2, 2016 19:15 — forked from timelyportfolio/README.md
nesting and summarizing in R and d3.js

Built with blockbuilder.org

Nesting and summarizing data is a very common task for data analysis. I thought it would be nice to view parallel ways of nesting and summarizing with both

  • R | tidyr and dplyr
  • JavaScript | d3.js ...v4 for fun

To avoid context switching, I'll take advantage of the R package V8. If you are an R user, then these d3.js gists might be helpful d3 nest examples and Mister Nester.

@abresler
abresler / diagrammer-bball-vis.R
Last active December 18, 2015 15:11
Simple visualization of NBA player movements using the DiagrammeR R package
library(DiagrammeR)
library(magrittr)
library(visNetwork)
moments <-
'https://gist.githubusercontent.com/rich-iannone/9c4e50cd5d811b841349/raw/65bc97ddac2f9e52a4252fcf2060007fe1afeb7d/moment.csv' %>%
read_csv()
# Generate the court
court <-
@abresler
abresler / world-cities-diagrammer.R
Created October 5, 2015 17:45 — forked from rich-iannone/world-cities-diagrammer.R
Demonstration code for plotting a graph of world cities along with country borders with the DiagrammeR R package.
# Installation
#install.packages("devtools")
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
# Create a graph of border coordinates
country_graph <- country_graph()
# Read in a CSV with location and population data for cities all over the world
@abresler
abresler / neuralnetR.R
Created September 24, 2015 16:35 — forked from mick001/neuralnetR.R
A neural network exaple in R. Full article at:
# Set a seed
set.seed(500)
library(MASS)
data <- Boston
# Check that no data is missing
apply(data,2,function(x) sum(is.na(x)))
# Train-test random splitting for linear model

Although very handy and useful, I think most new R developers do not even know that tables exist. They are a little tricky to use, but they offer some nice functionality. These tables become even more useful when we can visualize them as networks. This little bit of code is a rough first attempt at converting tables to network nodes and edges.

live example

### Title: Back to basics: High quality plots using base R graphics
### An interactive tutorial for the Davis R Users Group meeting on April 24, 2015
###
### Date created: 20150418
### Last updated: 20150423
###
### Author: Michael Koontz
### Email: [email protected]
### Twitter: @michaeljkoontz
###
#devtools::install_github("rstudio/leaflet", ref="feature/color-legend")
library(leaflet)
library(RColorBrewer)
set.seed(100)
pdf <- data.frame(Latitude = runif(100, -90,90), Longitude = runif(100, -180,180))
#make a property with colors
pdf$Study <- rep(1:10,10)
#need to create a pal using colorbin
# Get the latest version of 'DiagrammeR'
install_github("rich-iannone/DiagrammeR")
# Create a 'nodes' data frame
nodes <- sample(1:100, 100, replace = FALSE)
style <- rep("filled", 100)
fillcolor <- c(rep("turquoise", 20), rep("pink", 20),
rep("ochre", 20), rep("gray40", 20),
@abresler
abresler / dogs.R
Last active December 18, 2015 15:37
# Reading in 'dogs.csv'
# Created by Alex Bresler, available at:
# https://github.com/abresler/abresler.github.io/blob/master/blog/2015/february/exploring_agility_show/data/dogs.csv
dogs <- read.csv("dogs.csv", header = TRUE, stringsAsFactors = FALSE)
# Setting a numeric id
node_id <- 1:nrow(dogs)
# Getting unique values for the 'breed' column
unique_node_2 <- unique(dogs$breed)
@abresler
abresler / pagerank.R
Last active December 18, 2015 15:37 — forked from andrie/pagerank.R
## Analyze R packages for popularity, using pagerank algorithm
# Inspired by Antonio Piccolboni, http://piccolboni.info/2012/05/essential-r-packages.html
library(miniCRAN)
library(igraph)
library(magrittr)
# Download matrix of available packages at specific date ------------------