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
############################################################################# | |
## DOWNLOAD and PARSE data | |
base_url <- "http://trackshackresults.com/peachtree/results/2015/ptresults.php" | |
divisions_map <- read.table(text = ' | |
Ind Div Division | |
1 1B "****MEN -- OPEN****" | |
2 1G "****WOMEN -- OPEN****" |
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
ok.comma <- function(FUN) { | |
function(...) { | |
arg.list <- as.list(sys.call())[-1L] | |
len <- length(arg.list) | |
if (len > 1L) { | |
last <- arg.list[[len]] | |
if (missing(last)) { | |
arg.list <- arg.list[-len] | |
} | |
} |
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
decode(basket, search = c("banana", "orange"), | |
replace = c("apple", "pineapple")) | |
# [1] "apple" "apple" "lemon" "pineapple" "pineapple" "pear" "cherry" | |
decode(basket, search = c("banana", "orange"), | |
replace = c("apple", "pineapple"), | |
default = "fig") | |
# [1] "fig" "apple" "fig" "pineapple" "pineapple" "fig" "fig" |
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
basket <- c("apple", "banana", "lemon", "orange", | |
"orange", "pear", "cherry") | |
ifelse(basket == "banana", "apple", | |
ifelse(basket == "orange", "pineapple", | |
basket)) # or "fig")) | |
# [1] "apple" "apple" "lemon" "pineapple" | |
# [4] "pineapple" "pear" "cherry" |
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
decode <- function(x, search, replace, default = NULL) { | |
# build a nested ifelse function by recursion | |
decode.fun <- function(search, replace, default = NULL) | |
if (length(search) == 0L) { | |
function(x) if (is.null(default)) x else rep(default, length(x)) | |
} else { | |
function(x) ifelse(x == search[1L], replace[1L], | |
decode.fun(tail(search, -1L), | |
tail(replace, -1L), |
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
optical.art <- function(P, N, colors = brewer.pal(P, "Greys")) { | |
## This function creates an Op art figure as can be found on | |
## http://r-de-jeu.blogspot.com/ | |
## | |
## Inputs: | |
## - P: (integer) number of starting points | |
## - N: (integer) number of semi-lines starting from each point. | |
## For best results, N should be a multiple of P | |
## - colors: vector of colors for filling polygons. |
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
image.gallery <- function(url, ncol = 3L) { | |
## This function reformats the contents of a Craigslist search result URL | |
## into an image gallery, opened into the default browser | |
## | |
## Inputs: | |
## - url: a Craigslist search URL as created by search.url | |
## - ncol: the number of columns for the output image gallery | |
## | |
## Output: none. As a side effect, a browser is opened. |
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(wordcloud) | |
wordcloud(packages.df$`Package Name`, | |
packages.df$Users, | |
max.words = 50, | |
colors = brewer.pal(9, "Greens")[4:9]) |
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(plyr) | |
library(XML) | |
# build a vector of URL pages we'll want to use | |
urls <- paste("http://crantastic.org/popcon?page=", 1:10, sep = "") | |
# scrape all the data from the URLs into one big data.frame | |
packages.df <- ldply(urls, function(url)readHTMLTable(url)[[1]]) | |
# turn the "Users" column from factor to numeric |