Skip to content

Instantly share code, notes, and snippets.

View PhillRob's full-sized avatar
🌐
At the office (for most of the time)

Philipp R PhillRob

🌐
At the office (for most of the time)
View GitHub Profile
@PhillRob
PhillRob / stratifiedDT.R
Last active August 29, 2015 14:27 — forked from mrdwab/stratifiedDT.R
Attempt to rewrite stratified for `data.table`. The `data.frame` version can be found at https://gist.github.com/mrdwab/6424112
stratifiedDT <- function(indt, group, size, select = NULL,
replace = FALSE, keep.rownames = FALSE,
bothSets = FALSE) {
require(data.table)
if (is.numeric(group)) group <- names(indt)[group]
if (!is.data.table(indt)) indt <- as.data.table(
indt, keep.rownames = keep.rownames)
if (is.null(select)) {
indt <- indt
} else {