Skip to content

Instantly share code, notes, and snippets.

library(reshape2)
N <- 100000L
d.m <- data.frame(q1=runif(N), q2=runif(N), q3=runif(N),
f=sample(letters, N, replace=T), w=runif(N))
print(head(d.m))
print(summary(d.m))
sessionInfo()
---
title: "Test"
output: html_document
---
```{r setup}
knitr::dep_prev()
summary(cars)
```
m1 <- png::readPNG("~/Downloads/m1.png")
m2 <- png::readPNG("~/Downloads/m2.png")
m1r <- m1[,,1]
m2r <- m2[,,1]
m1r1 <- m1r[,1]
m2r1 <- m2r[,1]
sim <- llply(
@krlmlr
krlmlr / gist:80f5050a33e98de23671
Created April 14, 2015 21:25
Bootstrap wercker for R packages
curl http://krlmlr.github.io/makeR/install | sh
make dt_test
make init-wercker
make init-gh-pages
all: results.log
results.log: benchmark.R Makefile
r -p benchmark.R | tee results.log
@krlmlr
krlmlr / cut2.R
Last active December 11, 2015 11:28 — forked from mrdwab/cut2.R
cut2 <- function (x, breaks, labels = NULL, include.lowest = FALSE, right = TRUE,
dig.lab = 3, ordered_result = FALSE, ...)
{
if (!is.numeric(x))
stop("'x' must be numeric")
if (length(breaks) == 1L) {
if (is.na(breaks) || breaks < 2L)
stop("invalid number of intervals")
nb <- as.integer(breaks + 1)
dx <- diff(rx <- range(x, na.rm = TRUE))
dat <- read.table(text="VARIABLES DATE DATA
V1 1/03/2012 1000
V1 1/04/2012 1500
V1 1/12/2012 2600
V2 1/03/2012 900
V2 1/04/2012 1200
V2 1/12/2012 1000
V3 1/03/2012 200", header = TRUE)
@krlmlr
krlmlr / .autoscreen
Last active December 17, 2015 05:59 — forked from anonymous/.autoscreen
# Auto-screen invocation. see: http://taint.org/wk/RemoteLoginAutoScreen
# if we're coming from a remote SSH connection, in an interactive session
# then automatically put us into a screen(1) session. Only try once
# -- if $STARTED_SCREEN is set, don't try it again, to avoid looping
# if screen fails for some reason.
if [ "$TERM" != screen -a "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x -a "${SSH_TTY:-x}" != x -a "$DISPLAY" == "" ]
then
echo "Auto-starting screen."
# Set the window title to HOSTNAME
DROP TABLE IF EXISTS ind1_2000 CASCADE;
CREATE TABLE ind1_2000 (id integer, ind1 float);
ALTER TABLE ind1_2000 ADD PRIMARY KEY (id);
INSERT INTO ind1_2000 VALUES (1, 0.0);
INSERT INTO ind1_2000 VALUES (2, 0.3);
INSERT INTO ind1_2000 VALUES (3, 1.1);
VACUUM ANALYZE ind1_2000;
DROP TABLE IF EXISTS ind2_2000 CASCADE;
CREATE TABLE ind2_2000 (id integer, ind2 float);
template <class Fun>
class ScopeGuard {
Fun f_;
bool active_;
public:
ScopeGuard(Fun f)
: f_(std::move(f))
, active_(true) {
}
~ScopeGuard() { if (active_) f_(); }