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
#Code to re-create John Hussman's Recession warning index | |
#http://www.hussmanfunds.com/wmc/wmc110801.htm | |
#R code by Zach Mayer | |
rm(list = ls(all = TRUE)) #CLEAR WORKSPACE | |
library(quantmod) | |
################################################# | |
# 1. Credit spreads | |
################################################# |
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
INSERT INTO pet (id, name, breed, age, dead) | |
VALUES (5, "shimmer", "unicorn", 500, 1); | |
INSERT INTO pet (id, name, breed, age, dead) | |
VALUES (6, "water bottle", "faun", 4, 1); | |
INSERT INTO pet (id, name, breed, age, dead) | |
VALUES (7, "luis", "elephant", 282, 1); | |
INSERT INTO pet (id, name, breed, age, dead) |
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
# helpful functions for classification/regression training | |
# http://cran.r-project.org/web/packages/caret/index.html | |
library(caret) | |
# get indices of data.frame columns (pixels) with low variance | |
badCols <- nearZeroVar(train) | |
print(paste("Fraction of nearZeroVar columns:", round(length(badCols)/length(train),4))) | |
# remove those "bad" columns from the training and cross-validation sets | |
train <- train[, -badCols] |
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
LinearizeNestedList <- function(NList, LinearizeDataFrames=FALSE, | |
NameSep="/", ForceNames=FALSE) { | |
# LinearizeNestedList: | |
# | |
# https://sites.google.com/site/akhilsbehl/geekspace/ | |
# articles/r/linearize_nested_lists_in_r | |
# | |
# Akhil S Bhel | |
# | |
# Implements a recursive algorithm to linearize nested lists upto any |
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
Various handy bits and bobs relating to SQL (and the mySQL RDBMS in particular). | |
# Dump all databases from CLI: | |
$ mysqldump -h [server] -u root --password=password --default-character-set=utf8 --set-charset --all-databases > all_dbs.sql | |
# Restore all databases from CLI: | |
$ mysql -u root --password=password --default-character-set=utf8 --set-charset < all_dbs.sql |
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
PostgreSQL Cheat Sheet | |
====================== | |
CREATE DATABASE | |
CREATE DATABASE dbName; | |
CREATE TABLE (with auto numbering integer id) | |
CREATE TABLE tableName ( | |
id serial PRIMARY KEY, | |
name varchar(50) UNIQUE NOT NULL, |
A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
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
## Load libraries | |
library(XML) | |
library(dplyr) | |
library(RCurl) | |
## Get the results for a specific term | |
scrape_term = function(search_term,npages){ | |
base_url = "http://scholar.google.com/scholar?" | |
search_string = paste0("q=",paste0(strsplit(search_term," ")[[1]],collapse="+")) | |
dat = data.frame(NA,nrow=10*npages,ncol=3) |
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
SQL | |
Statements always end with a semi-colon ; | |
Statement breakdown: | |
CREATE TABLE table_name ( | |
column_1 data_type, | |
column_1 data_type | |
); |
OlderNewer