Skip to content

Instantly share code, notes, and snippets.

View geneorama's full-sized avatar

Gene Leynes geneorama

View GitHub Profile
#include<iostream>
#include<cmath>
#include<stdlib.h>
using namespace std;
int main() {
int n,i;
int is_prime = true;
cout << "Enter a number and press ENTER: ";
@geneorama
geneorama / gist:4998308
Created February 20, 2013 19:14
Data.table column conversion question

I want to update a group of columns programmatically. This is simple using data.frame, but in data.table this requires a confusing combination of substitute, as.symbol, and eval.

Am I doing this right?

Simple example:

## GENERATE DATA
library(data.table)
set.seed(1)

dt <- data.table(

@geneorama
geneorama / index.html
Last active August 29, 2015 14:06
LeafletExample
// Gene Leynes 2014-09-23
// Example taken (borrowed) from http://leafletjs.com/
// I'm using this example to test http://bl.ocks.org/
// (this should now be index.html)
<!DOCTYPE html>
<meta charset="utf-8">
<style>
// create a map in the "map" div, set the view to a given place and zoom
@geneorama
geneorama / index.html
Last active August 29, 2015 14:06
Leaflet_example_3
// Gene Leynes 2014-09-23 SOME EDITS
// Example taken (borrowed) from http://leafletjs.com/
// I'm using this example to test http://bl.ocks.org/
// (this should now be index.html)
<!DOCTYPE html>
<meta charset="utf-8">
<style>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
@geneorama
geneorama / index.html
Created September 23, 2014 17:08
leaflet_fullexample
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Quick Start Guide Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../dist/leaflet.css" />
@geneorama
geneorama / gist:7d7ec0a1884f9b4defe2
Last active August 29, 2015 14:22
Reshaping with data.table
## Using example from Arun's presentation:
## https://twitter.com/MattDowle/status/605881443491774464
##------------------------------------------------------------------------------
## INITIALIZE
## Load library, copy melt out of data.table, and create data example
##------------------------------------------------------------------------------
library(data.table) ## v1.9.4
melt <- data.table:::melt.data.table ## Something I usually do, just in case
rm(list=ls())
library(randomForest)
################################################################################
## EXAMPLE 1 (ver_1)
## Two data frames are created (test and train)
## They have their own independent factor levels, and some of the levels in
## `test_ver1` do not appear in `train_ver1`
##
@geneorama
geneorama / index.html
Last active October 10, 2016 17:22
WNV_Map_with_counts
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
@geneorama
geneorama / label_encoding_beginning
Last active February 1, 2018 01:13
Example of how to encode data frame with string / factor levels into numeric factor levels, and store the encoding.
##
## gene leynes 2016-10-28
##
## Label encoder based on
## http://stackoverflow.com/questions/38620424/label-encoder-functionality-in-r
##
encoding_matrix <- function(df, plug_missing = TRUE, missing_string = "MISSING"){
df <- as.data.frame(df)
cols <- which(sapply(df, is.character) | sapply(df, is.factor))
@geneorama
geneorama / glmnet_girdsearch.R
Created November 2, 2016 13:34
Heap your criticisms here
grid_glmnet <- expand.grid(alpha = c(0, .2, .4, .6, .8, 1),
# lambda = seq(.01, .2, length = 40))
#lambda = rev(exp(seq(log(.00001), log(200), length=10)))
lambda = rev(exp(seq(log(.00001), log(20), length=20))))
results_glmnet <- list()
# g <- unique(dat$grp)[1]
# i <- 1
for(i in 1:nrow(grid_glmnet)){
print(i)