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(ggplot2) | |
### Imagine a coin is flipped 100 times | |
### You get 60 heads | |
### How can you assess if the coin is fair or not? | |
# Set up the plot | |
binom_density <- dbinom(0:100,100,.5) | |
flips <- data.frame(flip_count = 0:100, density = binom_density) |
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
num2letter = {"2":"abc", "3":"def", "4":"ghi", "5":"jkl", "6":"mno", | |
"7":"pqrs", "8":"tuv", "9":"wxyz"} | |
def keys2letters(key_presses): | |
results = [x for x in num2letter[key_presses[0]]] | |
if len(key_presses) <= 1: | |
return(results) | |
else: | |
for x in key_presses[1:]: |
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
### Define terms to understand investment potentional | |
### This function will simulate scenarios to compare renting to buying and allow us to make an informed financial decision | |
## Parameters of the model (some are hard coded but can still be changed) | |
## r - Annual appreciation rate | |
## term - Term you want to own the house for (in months) | |
## house_cos - cost of the house in dollars | |
## ir - Interest rate of my mortgage | |
## closing - total closing costs |
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
### Define terms to understand investment potentional | |
### This function will simulate scenarios to compare renting to buying and allow us to make an informed financial decision | |
## Parameters of the model (some are hard coded but can still be changed) | |
## r - Annual appreciation rate | |
## term - Term you want to own the house for (in months) | |
## house_cos - cost of the house in dollars | |
## ir - Interest rate of my mortgage | |
## closing - total closing costs |
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("dplyr") | |
library("audio") | |
notes <- c(A = 0, B = 2, C = 3, D = 5, E = 7, F = 8, G = 10) | |
pitch <- "D D E D G F# D D E D A G D D D5 B G F# E C5 C5 B G A G" | |
duration <- c(rep(c(0.75, 0.25, 1, 1, 1, 2), 2), | |
0.75, 0.25, 1, 1, 1, 1, 1, 0.75, 0.25, 1, 1, 1, 2) | |
bday <- data_frame(pitch = strsplit(pitch, " ")[[1]], | |
duration = duration) |
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(devtools) | |
install_github("ropensci/prism") | |
library(leaflet) | |
library(raster) | |
library(prism) | |
## Set default path for raster files | |
options(prism.path = "~/prismtmp") | |
get_prism_normals(type="tmean",resolution = "4km",annual =T, keepZip=F) |
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
#' The length of a string (in characters). | |
#' | |
#' @param string input character vector | |
#' @return numeric vector giving number of characters in each element of the | |
#' character vector. Missing strings have missing length. | |
#' @seealso \code{\link{nchar}} which this function wraps | |
#' @export | |
#' @examples | |
#' str_length(letters) | |
#' str_length(c("i", "like", "programming", NA)) |
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
ptm <- proc.time() | |
sum(1:10000000 == 4) | |
proc.time() - ptm | |
>user system elapsed | |
> 0.143 0.037 0.179 | |
ptm <- proc.time() | |
sum(1:10000000 %in% 4) | |
proc.time() - ptm |
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
#' Extract mentions | |
#' @description extract all the mentions of other twitter users from a tweet | |
#' @param txt the text of your tweet | |
#' @export | |
mention_ext <- local({ | |
ment <- rep(NA,150) | |
f <- function(txt){ | |
if(!is.na(txt)){ |
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
#' A function to do gradient descent on arbitrarily sized linear models | |
#' @param Y a vector of response variables | |
#' @param X a design matrix of predictor variables | |
#' @param alpha the gradient descent step size | |
#' @param init the seed to start off for estimating parameters, must be the same size as the columns in X | |
#' @param failure the number of iterations after which to say convergence has failed | |
#' @param epsilon the difference in size between loss function iterations after which to say convergence has been reached. | |
linear_gd <- function(Y, X, alpha, init = runif(dim(X)[2],-10,10),failure = 10000,epsilon = 0.0001){ | |
theta_new <- init |
NewerOlder