Skip to content

Instantly share code, notes, and snippets.

@seankross
seankross / algorithm.R
Created November 30, 2015 21:52
Kross-Kross algorithm for filling a matrix with the coordinates of another matrix
A <- matrix(NA, nrow = 4, ncol = 7)
x <- function(A){
total_pairs <- nrow(A) * ncol(A)
rc <- matrix(NA, ncol = 2, nrow = total_pairs)
k <- r <- c <- 1
while (k <= total_pairs) {
rc[k, 1] <- r
rc[k, 2] <- c
k <- k+1
## Universities
Data and Story Librbary
Berkley Data Lab
UCLA Statistics Data Sets
## General Data
freebase.com
infochimps.org
numbrary.com
aggdata.com
@seankross
seankross / wtp.R
Last active January 31, 2016 07:51
We The People
library(dplyr)
library(jsonlite)
pets <- list()
for(i in 1:6){
offset_ <- seq(0, 5000, by = 1000)
query_ <- paste0("https://api.whitehouse.gov/v1/petitions.json?limit=1000&offset=", offset_[i])
pets[[i]] <- fromJSON(query_)[[2]]
Sys.sleep(0.5)
@seankross
seankross / hist_and_norm.R
Created March 3, 2016 23:01
Draw normal distribution on histogram of any dataset
# Draw a normal distribution curve on top of a histogram
# of any vector
#
# @param data A numeric vector
hist_and_norm <- function(data){
hist_min <- mean(data) - 4*sd(data)
hist_max <- mean(data) + 4*sd(data)
normalx <- seq(hist_min, hist_max, by = 1)
normaly <- dnorm(normalx, mean = mean(data), sd = sd(data))
@seankross
seankross / splines.R
Created April 4, 2016 04:13
Plot Predicted Values
library(splines)
set.seed(3-29-2016)
X <- rnorm(1000)
Y <- rnorm(1000)
model <- lm(Y ~ ns(X, 6))
lo <- loess(Y ~ X, span = .75)
@seankross
seankross / simple_rmd
Last active November 10, 2016 16:03
Gists for Developing Data Products
```{r}
# Write some R code here!
x <- rnorm(10)
x^2
plot(x)
```
@seankross
seankross / test.R
Last active November 15, 2016 15:09
iris ROC
library(dplyr)
library(forcats)
library(ggplot2)
iris.small <- datasets::iris %>%
dplyr::filter(Species != "setosa") %>%
dplyr::mutate(Species = fct_drop(Species)) %>%
dplyr::group_by(Species) %>%
dplyr::summarize(avg_sl = mean(Sepal.Length),
avg_sw = mean(Sepal.Width),
@seankross
seankross / wifi.sh
Last active April 6, 2017 15:58
power cycle wifi
alias wifi='networksetup -setairportpower en0 off;sleep 2;networksetup -setairportpower en0 on'
#' @importFrom shiny
#' @import miniUI
codefinch_app <- function(){
ui <- miniPage(
gadgetTitleBar("Codefinch: Tweet Your Code",
right = miniTitleBarButton("tweet_it", "Send Tweet", primary = TRUE)),
miniContentPanel(
fillCol(flex = c(5, 2),
imageOutput("code_png"),
fillRow(flex = c(2, 1),