Skip to content

Instantly share code, notes, and snippets.

@seankross
seankross / Session 1
Created Nov 11, 2012
Live R Coding with Cohen
View Session 1
# Cohen
setwd("~/Desktop/R")
source("~/Desktop/R/floridaModel.R")
floridaModel('F','GM',c(11,8,2011),c(11,8,2012))
@seankross
seankross / R Plot Differences
Created Dec 2, 2012
Plots difference between two stocks
View R Plot Differences
setwd('~/Desktop/R/Inputs')
getYahooCsv <- function(startDate, endDate, ticker){
  string <- paste("http://ichart.finance.yahoo.com/table.csv?s=",ticker,
                  "&a=",startDate[1]-1,"&b=",startDate[2],"&c=",startDate[3],
                  "&d=",endDate[1]-1,"&e=",endDate[2],"&f=",endDate[3],"&g=d&ignore=.csv",
                  sep="")
  
  return (read.csv(string))
}
@seankross
seankross / Sieve of Eratosthenes.R
Last active May 24, 2020
Counting primes using the Sieve of Eratosthenes in R
View Sieve of Eratosthenes.R
# The Sieve of Eratosthenes
# Given a number greater than zero this function will return a list of primes between 2 and the number given as argument.
sieveOfEratosthenes <- function(num){
values <- rep(TRUE, num)
values[1] <- FALSE
prev.prime <- 2
for(i in prev.prime:sqrt(num)){
values[seq.int(2 * prev.prime, num, prev.prime)] <- FALSE
prev.prime <- prev.prime + min(which(values[(prev.prime + 1) : num]))
View Where to find data
## Universities
Data and Story Librbary
Berkley Data Lab
UCLA Statistics Data Sets
## General Data
freebase.com
infochimps.org
numbrary.com
aggdata.com
@seankross
seankross / Histograms in R
Last active Dec 21, 2015
Making a histogram in R
View Histograms in R
# Assuming you have a file called Workbook2.csv on your desktop
Workbook2 <- read.table("~/Desktop/Workbook2.csv", quote="\"")
colors = c("red", "yellow", "green", "violet", "orange")
hist(Workbook2$V1, main = "Title", xlab = "X-axis", ylab = "Y-axis", col = colors)
@seankross
seankross / Update Fork.md
Last active Aug 13, 2019
Update a Github Fork from the Original Repo
View Update Fork.md

Taken from here

Add remonte branch:

git remote add --track master mleung git://github.com/mleung/feather.git

Verify:

git remote

@seankross
seankross / init.md
Created Feb 5, 2014
Initializing GitHub repository
View init.md

Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/seankross/womp.git
git push -u origin master
View tweet_dumper.py
#!/usr/bin/env python
# encoding: utf-8
import tweepy #https://github.com/tweepy/tweepy
import csv
#Twitter API credentials
consumer_key = ""
consumer_secret = ""
access_key = ""
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<style>
@import url(https://raw.github.com/jasondavies/d3-parsets/master/d3.parsets.css);
body {
font-family: sans-serif;
font-size: 16px;
width: 960px;
margin: 1em auto;
View mtcars.csv
model mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4
Mazda RX4 Wag 21 6 160 110 3.9 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.44 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1
Duster 360 14.3 8 360 245 3.21 3.57 15.84 0 0 3 4
Merc 240D 24.4 4 146.7 62 3.69 3.19 20 1 0 4 2
Merc 230 22.8 4 140.8 95 3.92 3.15 22.9 1 0 4 2
You can’t perform that action at this time.