Skip to content

Instantly share code, notes, and snippets.

View trinker's full-sized avatar

Tyler Rinker trinker

View GitHub Profile
@pdparker
pdparker / knitr
Last active August 29, 2015 14:15
knitr makefile
# Transform .Rmd files to slidy files
.SUFFIXES: .Rmd .html .md
all: Day1Part1-Introduction.md Day1Part1-Introduction.html Day1Part1-session2.md Day1Part1-session2.html \
Day1Part1-session3.md Day1Part1-session3.html Day1Part2-session1.md Day1Part2-session1.html \
Day1Part2-session2.md Day1Part2-session2.html
#markdown
%.md: %.Rmd
@hadley
hadley / advise.md
Created February 13, 2015 21:32
Advise for teaching an R workshop

I think the two most important messages that people can get from a short course are:

a) the material is important and worthwhile to learn (even if it's challenging), and b) it's possible to learn it!

For those reasons, I usually start by diving as quickly as possible into visualisation. I think it's a bad idea to start by explicitly teaching programming concepts (like data structures), because the pay off isn't obvious. If you start with visualisation, the pay off is really obvious and people are more motivated to push past any initial teething problems. In stat405, I used to start with some very basic templates that got people up and running with scatterplots and histograms - they wouldn't necessary understand the code, but they'd know which bits could be varied for different effects.

Apart from visualisation, I think the two most important topics to cover are tidy data (i.e. http://www.jstatsoft.org/v59/i10/ + tidyr) and data manipulation (dplyr). These are both important for when people go off and apply

@Pakillo
Pakillo / word-character-count-Rstudio.md
Last active June 25, 2020 21:24
Count words and characters in Rstudio

As far as I know Rstudio does not count words or characters at the moment, which would be useful particularly when writing Rmarkdown.

This is a quick shortcut using word_count and character_count functions from qdap package. See below for two wrapper functions that simplify their use.

library("qdap")

Just select and copy the text to the clipboard and then run in the console:

@jennybc
jennybc / 2014-09-18_numeric-index-gotcha.md
Last active August 29, 2015 14:06
How quickly indexing with numeric can burn you

Inspired by recent @johnmyleswhite tweets on indexing (though they focus more on NA stuff)

My standard advice to R novices is "don't worry about numeric vs integer too much, for now", but I just created an indexing example that scares me.

I did not realize it was sooo easy to create this gotcha when indexing with numeric (which I know is not a great idea).

@bryangoodrich
bryangoodrich / RegularizedGradientDescent.R
Created August 26, 2014 05:45
Regularized Gradient Descent Logistic Classifier with Decision Boundary
loadInput <- function() {
structure(c(0.051267, -0.092742, -0.21371, -0.375, -0.51325,
-0.52477, -0.39804, -0.30588, 0.016705, 0.13191, 0.38537, 0.52938,
0.63882, 0.73675, 0.54666, 0.322, 0.16647, -0.046659, -0.17339,
-0.47869, -0.60541, -0.62846, -0.59389, -0.42108, -0.11578, 0.20104,
0.46601, 0.67339, -0.13882, -0.29435, -0.26555, -0.16187, -0.17339,
-0.28283, -0.36348, -0.30012, -0.23675, -0.06394, 0.062788, 0.22984,
0.2932, 0.48329, 0.64459, 0.46025, 0.6273, 0.57546, 0.72523,
0.22408, 0.44297, 0.322, 0.13767, -0.0063364, -0.092742, -0.20795,
-0.20795, -0.43836, -0.21947, -0.13882, 0.18376, 0.22408, 0.29896,
@MrFlick
MrFlick / test.withX.R
Last active August 29, 2015 14:01
withX.R: Allows you to perform multiple operations on a temporary object without having to create a temporary variable
# withX() will create an environment for the first parameter and all of your named parameters
# if the first parameter is not named, it will be called "X" in the enviroment
# there may be exactly one unnamed expression
# this unnamed parameter will be eval'ed in the envir defined by your named parameters
# If no object is returned from the expression, the newest value of the first parameter is returned invisibly
# this can avoid repeating awkward expressions
#this is a lot like `with()` but instead of working within the variable,
# the value itself is added to the enviroment as a variable
@mrdwab
mrdwab / cSplit.R
Last active March 14, 2023 05:03
The faster version of `concat.split` that makes use of `data.table` efficiency.
cSplit <- function(indt, splitCols, sep = ",", direction = "wide",
makeEqual = NULL, fixed = TRUE, drop = TRUE,
stripWhite = FALSE) {
message("`cSplit` is now part of the 'splitstackshape' package (V1.4.0)")
## requires data.table >= 1.8.11
require(data.table)
if (!is.data.table(indt)) setDT(indt)
if (is.numeric(splitCols)) splitCols <- names(indt)[splitCols]
if (any(!vapply(indt[, splitCols, with = FALSE],
is.character, logical(1L)))) {
@leeper
leeper / slopegraph.r
Last active December 26, 2015 13:29
Edward Tufte-style Slopegraphs in R. Find the current version of this code here: https://github.com/leeper/slopegraph
# R Function to Draw Edward Tufte-style Slopeplots
slopegraph <-
function(
df,
xlim = c(.5,ncol(df)+.5),
ylim = c(min(df)-diff(range(df))/100,max(df)+diff(range(df))/100),
main = NULL,
bty = 'n',
yaxt = 'n',