This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Scrapes CRAN archives to determine the number of packages per release | |
# Create a list of pages to scrape, including both archive and current | |
extract_url <- function(){ | |
url <- list( | |
archive = "https://cran-archive.r-project.org/bin/windows/contrib/", | |
active = "https://cran.r-project.org/bin/windows/contrib/" | |
) | |
get_urls <- function(url){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
dat <- read.csv("world records.csv", stringsAsFactors = FALSE) | |
# Clean and transform the data -------------------------------------------- | |
track <- within(dat, { | |
Time <- as.numeric(Time.in.hours) | |
Date <- as.Date(Date, format = "%d-%b-%y") | |
Speed <- Distance / Time | |
logDistance <- log10(Distance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(magrittr) | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
set.seed(1) | |
dat <- r_data_frame(12, | |
name, | |
r_series(grade, 100, relate = "+1_6") | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(doSNOW) | |
library(tcltk) | |
cl <- makeSOCKcluster(2) | |
registerDoSNOW(cl) | |
pb <- txtProgressBar(max=100, style=3) | |
progress <- function(n) setTxtProgressBar(pb, n) | |
opts <- list(progress=progress) | |
r <- foreach(i=1:100, .options.snow=opts) %dopar% { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Connect to SQL Server using RODBC | |
library(RODBC) | |
library(magrittr) | |
# Connect to SQL Server using RODBC ------------------ | |
sqlHost <- "DAA136209339.sys-sqlsvr.local" | |
sqlDatabase <- "RevoTestDB" | |
dsnString <- "driver={SQL Server};server=%s;database=%s;trusted_connection=true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Objective | |
# | |
# Fit a gamma distribution knowing that: | |
# - 20% fall below 15 days | |
# - 80% fall below 60 days | |
# Inspired by http://www.johndcook.com/blog/2010/01/31/parameters-from-percentiles/ | |
x <- c(0.2, 0.8) | |
y <- c(15, 60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(repr) | |
# Change plot size to 4 x 3 | |
options(repr.plot.width=4, repr.plot.height=3) | |
curve(sin(x), from = 0, to=2*pi, n = 100) | |
# Change plot size to 8 x 3 | |
options(repr.plot.width=8, repr.plot.height=3) | |
curve(sin(x), from = 0, to=4*pi, n = 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate data in the form of a sine wave | |
set.seed(1) | |
n <- 1e3 | |
dat <- data.frame( | |
x = 1:n, | |
y = sin(seq(0, 5*pi, length.out = n)) + rnorm(n=n, mean = 0, sd=0.1) | |
) | |
approxData <- data.frame( |