Skip to content

Instantly share code, notes, and snippets.

View andrie's full-sized avatar

Andrie de Vries andrie

View GitHub Profile
@andrie
andrie / archimedes-spiral.R
Last active August 29, 2015 14:22
archimedes-spiral
# Based on archimedes spiral
# Inspired by https://www.youtube.com/watch?v=SEiSloE1r-A
# The surprising beauty of mathematics | Jonathan Matte | TEDxGreensFarmsAcademy
# See http://en.wikipedia.org/wiki/Archimedean_spiral
rotate <- function(theta){
matrix(
c(cos(theta), -sin(theta),
sin(theta), cos(theta)
),
@andrie
andrie / SO-100K.R
Last active August 29, 2015 14:25
Analysing questions tagged R on StackOverflow
# StackOverflow query at
# https://data.stackexchange.com/stackoverflow/query/338993/r-trends-questions-per-tag-per-month#resultSets
# Import data -------------------------------------------------------------
url <- "https://data.stackexchange.com/stackoverflow/csv/437426"
dat <- read.csv(url)
dat$Month <- as.Date(dat$Month)
head(dat)
@andrie
andrie / popular-stackoverflow-tags.R
Created July 29, 2015 13:35
Analyse stackoverflow tags of top 10 languages
@andrie
andrie / contracted_graph.R
Created August 5, 2015 20:51
Contracted and simplified network graph
library(igraph)
# Download prepared igraph file from github
gs <- readRDS("pdb/depGraph-CRAN.rds")
set.seed(42)
# Compute communities (clusters)
cl <- walktrap.community(gs, steps = 5)
cl$degree <- (degree(gs)[cl$names])
library(parallel)
set.seed(1)
m <- 10000
n <- 2000
A <- matrix(runif (m*n),m,n)
setMKLthreads(1)
system.time(S <- svd (A,nu=0,nv=0))
# user system elapsed
@andrie
andrie / wakefield-example.R
Created October 28, 2015 17:09
wakefield example
library(magrittr)
library(dplyr)
library(tidyr)
library(ggplot2)
set.seed(1)
dat <- r_data_frame(12,
name,
r_series(grade, 100, relate = "+1_6")
)
@andrie
andrie / cleanGoogleTable.R
Last active November 20, 2016 12:43
Functions to read Google Docs spreadsheet into R
library(XML)
cleanGoogleTable <- function(dat, table=1, skip=0, ncols=NA, nrows=-1, header=TRUE, dropFirstCol=NA){
if(!is.data.frame(dat)){
dat <- dat[[table]]
}
if(is.na(dropFirstCol)) {
firstCol <- na.omit(dat[[1]])
if(all(firstCol == ".") || all(firstCol== as.character(seq_along(firstCol)))) {
dat <- dat[, -1]
}
@andrie
andrie / run-urbanek-benchmark-25.R
Created October 16, 2014 11:34
Source Simon Urbanek's benchmark v2.5 and capture total execution time
# Run Simon Urbanek's benchmark v2.5
cat("R version\n")
cat("=========\n")
print(R.version)
if(exists("Revo.version")) {
cat("Revo version")
cat("============")
print(Revo.version)
@andrie
andrie / install-and-try-wakefield.R
Created October 28, 2015 17:12
Install wakefield
# Install from github ----------------
# install.packages(c("chron", "ggplot2", "dplyr", "stringi"))
# devtools::install_github("trinker/wakefield")
# Create a sample data frame ---------
library(wakefield)
r_data_frame(
n = 500,
id,
@andrie
andrie / Can you keep a secret.R
Created July 29, 2017 21:36
Demo of `secret` package at UseR!2017
# load the package ----------------------------------------------------
# install.packages("secret")
library(secret)
library(magrittr)
# set up local user ---------------------------------------------------