This file contains hidden or 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
find . -name '.filename' -print -exec rm -r {} \; | |
# . = in current directory | |
# -name = file name to find | |
# -print = print the result's full file name to standard output | |
# -exec = execute the following command | |
# {} = fill in with the result of standard output | |
# \; = semicolon to terminate the -exec command, and the escape | |
# character so that the terminal doesn't treat the semicolon as a | |
# return character (used for stringing together multiple commands). |
This file contains hidden or 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
# The xkcd font used by the package xkcd (which provides a theme for ggplot2) | |
# is missing many characters and some characters don't seem to display correctly. | |
# An alternate xkcd-style font is Humor Sans, available free from | |
# \url{http://antiyawn.com/uploads/humorsans.html} | |
# The code below forces the use of Humor Sans instead of xkcd. | |
# The xkcd and ggplot2 packages are available from CRAN. | |
library(ggplot2) | |
library(xkcd) |
This file contains hidden or 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
# Create 2 replicates of 5 "words" generated from random characters, | |
# each "word" 5 - 15 characters long, with word length following a | |
# poisson distribution. | |
rep(replicate(5, paste(sample(letters, round(rpois(5000, lambda = 3)+5, 0), replace = FALSE), collapse = "")), 2) | |
# Sample output: | |
# [1] "rfexnwyjst" "vwtadhjnly" "ztfgvldo" "tmerol" "mcqhosap" "rfexnwyjst" "vwtadhjnly" "ztfgvldo" "tmerol" | |
#[10] "mcqhosap" |
This file contains hidden or 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
## For original file showing use of .env to add functions invisibly, see | |
## \link{http://gettinggeneticsdone.blogspot.com/2013/06/customize-rprofile.html} | |
## Load packages | |
#library(BiocInstaller) | |
## Don't show those silly significanct stars | |
#options(show.signif.stars=FALSE) | |
## Do you want to automatically convert strings to factor variables in a data.frame? |
This file contains hidden or 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
#' @title Sorting data frames factor levels for ggplot2 | |
#' @description Sorting a factor variable by a numeric variable. | |
#' In one case, each factor level is matched to one numeric value. | |
#' In the other case, each factor level is repeated across a second | |
#' grouping factor variable, and we want to sort only the | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
# Sort a factor by variable by a numeric variable |
This file contains hidden or 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
# Response to a post at Storytelling with Data: | |
# \url{http://www.storytellingwithdata.com/blog/orytellingwithdata.com/2015/07/align-against-common-baseline.html} | |
# Demonstrates | |
# * Cleveland-style dot plots (improvement over pie and bar charts) | |
# * Sorting categorical data by a numerical variable with more than one grouping variable | |
# * Highlighting differences between groups graphically | |
library(ggplot2) | |
library(scales) |
This file contains hidden or 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(dplyr) | |
# create a dummy dataframe with 100,000 groups and 1,000,000 rows | |
# and partition by group_id | |
df <- data.frame(group_id=sample(1:1e5, 1e6, replace=T), | |
val=sample(1:100, 1e6, replace=T)) %>% | |
group_by(group_id) | |
# filter rows with a value of 1 naively | |
system.time(df %>% filter(val == 1)) |
This file contains hidden or 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
# from Conrad Hacket | |
# Median hourly earnings | |
# \url{https://twitter.com/conradhackett/status/748884076493475840} | |
# makeover: convert from two groups of side-by-side vertical bar charts to a more readable dot plot | |
# Demonstrates: | |
# Use of in ggplot2 | |
# Creating dot plots | |
# Combining color and shape in a single legend | |
# Sorting a dataframe so that categorical data in one column is ordered by a second numerical column | |
# Note: resulting graph displays best at about 450 pixels x 150 pixels |
This file contains hidden or 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
# Based on a post at \url{http://www.walkingrandomly.com/?p=5254} | |
library(dplyr) | |
library(ggplot2) | |
library(minpack.lm) | |
# The data to fit | |
my_df <- data_frame(x = c(0,15,45,75,105,135,165,195,225,255,285,315), | |
y = c(0,0,0,4.5,19.7,39.5,59.2,77.1,93.6,98.7,100,100)) | |
# EDA to see the trend |
This file contains hidden or 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
##' Modifies 'data' by adding new values supplied in newDataFileName | |
##' | |
##' newDataFileName is expected to have columns | |
##' c(lookupVariable,lookupValue,newVariable,newValue,source) | |
##' | |
##' Within the column 'newVariable', replace values that | |
##' match 'lookupValue' within column 'lookupVariable' with the value | |
##' newValue'. If 'lookupVariable' is NA, then replace *all* elements | |
##' of 'newVariable' with the value 'newValue'. | |
##' |