Skip to content

Instantly share code, notes, and snippets.

View even4void's full-sized avatar

chl even4void

View GitHub Profile
@brendano
brendano / csv2tsv
Created February 13, 2009 09:12
csv2tsv
#!/usr/bin/env python2.6
"""
Input is Excel-style CSV. Either stdin or filename.
Output is honest-to-goodness tsv: no quoting or any \\n\\r\\t.
"""
from __future__ import print_function
import csv, sys
warning_count=0
;; significance testing with randomization
(use '(incanter core stats datasets charts))
(def data (to-matrix (get-dataset :plant-growth)))
;; Break the first column of the data into groups based on
;; treatment type (second column) using the group-by function.
(def groups (group-by data 1 :cols 0))
(t-test (first groups) :y (second groups))
(use '(incanter core processing))
;; simple interactive Processing example taken from processingjs.org website:
;; http://processingjs.org/source/basic-example/processingjs_basic-example.html
;; set up variable references to use in the sketch object
(let [radius (ref 50.0)
X (ref nil)
Y (ref nil)
@jlowin
jlowin / ggplot2.r
Created November 13, 2009 03:04
choropleth ggplot code
library(ggplot2)
#extract reference data
mapcounties <- map_data("county")
mapstates <- map_data("state")
#merge data with ggplot county coordinates
mapcounties$county <- with(mapcounties , paste(region, subregion, sep = ","))
mergedata <- merge(mapcounties, unemp_data, by.x = "county", by.y = "counties")
mergedata <- mergedata[order(mergedata$order),]
@hadley
hadley / reproducible.md
Created January 6, 2010 17:33
How to write a reproducible example

How to write a reproducible example.

You are most likely to get good help with your R problem if you provide a reproducible example. A reproducible example allows someone else to recreate your problem by just copying and pasting R code.

There are four things you need to include to make your example reproducible: required packages, data, code, and a description of your R environment.

  • Packages should be loaded at the top of the script, so it's easy to see which ones the example needs.

  • The easiest way to include data in an email is to use dput() to generate

@mxcl
mxcl / install_homebrew.markdown
Created March 6, 2010 15:14
Installs Homebrew to /usr/local so you don't need sudo to `brew install`
ks.default <- function(rows) seq(2, max(3, rows %/% 4))
many_kmeans <- function(x, ks = ks.default(nrow(x)), ...) {
ldply(seq_along(ks), function(i) {
cl <- kmeans(x, centers = ks[i], ...)
data.frame(obs = seq_len(nrow(x)), i = i, k = ks[i], cluster = cl$cluster)
})
}
all_hclust <- function(x, ks = ks.default(nrow(x)), point.dist = "euclidean", cluster.dist = "ward") {
data <- iris
d <- dist(scale(iris[, 1:4]))
h <- hclust(d, "ward")
data$ORDER <- order(h$order)
data$HEIGHT <- 0
data$LEVEL <- 0
data$POINTS <- 1
@mblondel
mblondel / perceptron.py
Last active April 21, 2024 13:42
Kernel Perceptron
# Mathieu Blondel, October 2010
# License: BSD 3 clause
import numpy as np
from numpy import linalg
def linear_kernel(x1, x2):
return np.dot(x1, x2)
def polynomial_kernel(x, y, p=3):
@drewconway
drewconway / google_counts.R
Created January 22, 2011 22:26
Function takes a string as parameter and returns the approximate number of Google search results containing that string
require(RCurl)
require(XML)
google.counts<-function(s){
search.url<-paste("http://www.google.com/search?q=",gsub(" ","+",s),sep="")
search.html<-getURL(search.url)
parse.search<-htmlTreeParse(search.html,useInternalNodes = TRUE)
search.nodes<-getNodeSet(parse.search,"//div[@id='resultStats']")
search.value<-strsplit(xmlValue(search.nodes[[1]])," ",fixed=TRUE)[[1]][2]
return(as.numeric(gsub(",","",search.value,fixed=TRUE)))