Skip to content

Instantly share code, notes, and snippets.

#Example for the kaggle forums.
library(FNN)
library(stats)
train <- read.csv("data/train.csv", header=TRUE, comment.char="")
test <- read.csv("data/test.csv", header=TRUE, comment.char="")
N <- 30000
set.seed(20140202)
trainingSet <- train[sample(1:nrow(train), N), ]
@Xachriel
Xachriel / AtcSearch.R
Created July 20, 2013 16:49
Searching ATC codes from WHO.
require(gdata)
require("RCurl")
require("XML")
AtcSearch <- function(AtcCodes){
#Function inside a function is bad practice...
#DummySearch searches for one atc code
DummySearch <- function(Code){
#A link to WHO search
@Xachriel
Xachriel / FM_bench3.R
Last active December 15, 2015 08:29
FM + data.table = success ?
#Using 64bit R 2.15.3
#Packages we are going to use
#download the packed data here: https://www.dropbox.com/s/c1rtcryp8p6500w/kms-2013-01-06-s.json.bz2
library(rjson)
library(data.table)
library(snow)
library(rbenchmark)
#set your WD where your unpackaged file is, or add path.
#Reading only partial data for this test, you can naturally do as you wish
@Xachriel
Xachriel / mc_fast_merging.R
Created March 24, 2013 08:24
Parallel fast.merging
#Multicore (mc) requires snow package as multicore isn't on windows...
require(snow)
mc.fast.merging = function(data.list, nparts, cluster){
if(!is.list(data.list)) stop("data.list isn't a list")
while(length(data.list) != 1){ #Loop until everything is merged
@Xachriel
Xachriel / a_merging_bench.R
Last active December 15, 2015 08:29
a merging bench
#Using 64bit R 2.15.3
#Packages we are going to use
library(rjson)
library(data.table)
library(rbenchmark)
#set your WD where your unpackaged file is, or add path.
#Reading only partial data for this test, you can naturally do as you wish
eve = readLines("kms-2013-01-06-s.json", n=3001)
@Xachriel
Xachriel / Nsheets.R
Created March 17, 2013 12:22
A stupid way of finding the number of sheets in a excel file
Nsheets = function(FILE){
FAILED = FALSE
i = 1
while(!FAILED){
test = try(read.xls(FILE, sheet=i), silent=TRUE)
if(class(test) == "try-error"){
stop(return(i-1))
@Xachriel
Xachriel / gist:4539962
Created January 15, 2013 16:39
Public starting script? Why the name is bad...
test.line = "some characters"
print(test.line)
test.fun = function(x){
print(x)
}