Skip to content

Instantly share code, notes, and snippets.

View gsk3's full-sized avatar

Ari Friedman gsk3

View GitHub Profile
@gsk3
gsk3 / Taxonomy of Conference Questions
Created February 28, 2015 22:59
Taxonomy of Conference Questions
# A Taxonomy of Conference Questions
# Ari B. Friedman
# www.abfriedman.com
# 5/26/2013
set.seed(8)
n <- 537
plot.main <- paste("Distribution of",n,"questions\n in a convenience sample of 15 conferences")
@gsk3
gsk3 / SAEMtwitter.R
Last active August 29, 2015 14:01
SAEM 2014 twitterlytics code
# Twitterlytics from SAEM14
setwd( file.path(.db,"misc","SAEMtwitter") )
library(twitteR)
library(tm)
library(wordcloud)
library(RColorBrewer)
library(magrittr)
library(ggplot2)
> X[Y, z := i.z]
> X
a b c g z
1: j j j 1 0.2486045
2: d d d 2 0.5365723
3: f f f 2 0.5365723
4: g g g 2 0.5365723
5: p p p 2 0.5365723
6: r r r 2 0.5365723
7: i i i 3 0.7218104
library(inline)
set.seed(123)
x <- sample(1:100,200, replace = TRUE)
cpp_src <- '
Rcpp::IntegerVector xa = clone(x); // Vector to be sampled
Rcpp::IntegerVector na(n); // Number of elements in solution
Rcpp::IntegerVector sa(s); // Sum of solution
@gsk3
gsk3 / SO_ggplot2_manycategories
Created February 8, 2013 15:15
Sample data for stackoverflow question
icc <- structure(list(entity = c(1L, 2L, 3L, 4L, 5L, 6L, 8L, 10L, 9L,
11L, 12L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L,
30L, 31L, 32L, 33L, 34L, 35L, 36L, 38L, 37L, 40L, 41L, 42L, 43L,
44L, 45L, 48L, 49L, 46L, 47L, 50L, 51L, 52L, 53L, 54L, 55L, 56L,
57L, 62L, 64L, 63L, 60L, 61L, 65L, 66L, 67L, 68L, 69L, 70L, 71L,
72L, 73L, 74L, 75L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L,
87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L,
100L, 102L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
115L, 116L, 118L, 113L, 114L, 119L, 120L, 121L, 123L, 124L, 125L,
2L, 7L, 19L, 13L, 14L, 15L, 16L, 17L, 18L, 39L, 55L, 58L, 59L,
xd.small <- list(structure(list(AREA = c(0.032314293570181, 2.57798549622157e-05,
0.0278274866221686, 0.0529413081379673, 0.0156142598310294, 0.0225160446846377
), PERIMETER = c(9.01604283481949, 0.0213118142069676, 1.00400802417332,
1.33323781389207, 1.26170249578337, 1.35222443633394), ZT01_D00_ = 2:7,
ZT01_D00_I = 1:6, ZCTA = structure(c(242L, 241L, 241L, 220L,
221L, 224L), .Label = c("35004", "35005", "35006", "35007",
"35010", "35014", "35016", "35019", "35020", "35022", "35023",
"35031", "35033", "35034", "35035", "35036", "35040", "35042",
"35043", "35044", "35045", "35046", "35049", "35051", "35052",
"35053", "35054", "35055", "35057", "35058", "35060", "35061",
blah blah
blah blah
#'Return a vector of the days of the week, in order
#'
#'@param start.day Day of the week to begin the week with (as a text item)
#'@return Character vector of length 7
#'@examples
#'daysofweek("Sunday")
#'
daysofweek <- function(start.day="Monday") {
wkdays <- c('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')
wkdays <- rep(wkdays,2)
#' Obtain the fractional part of a numeric
#'
#' Takes a numeric vector and returns a vector of the numbers after the decimal
#' place
#'
#' @param vec A numeric vector of any length
#' @return A vector of the same length as the input vec containing only the decimal component.
#' @examples
#' x <- runif(100)
#' fpart(x)