This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cSplit_e_new <- function (indt, splitCols, sep = ",", mode = "binary", type = "numeric", | |
drop = FALSE, fixed = TRUE, fill = NULL) { | |
indt <- setDT(copy(indt)) | |
if (is.numeric(splitCols)) splitCols <- names(indt)[splitCols] | |
if (length(sep) == 1) sep <- rep(sep, length(splitCols)) | |
if (length(sep) != length(splitCols)) stop("Wrong number of sep supplied") | |
if (length(mode) == 1) mode <- rep(mode, length(splitCols)) | |
if (length(mode) != length(mode)) stop("Wrong number of mode supplied") | |
if (any(!mode %in% c("binary", "value", "count"))) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trim_list <- function(x, relist = TRUE, convert = FALSE) { | |
x <- replace(x, lengths(x) == 0, NA_character_) | |
y <- unlist(x, use.names = FALSE) | |
y[!nzchar(y)] <- NA_character_ | |
out <- trim_vec(y, TRUE) | |
if ((attr(out, "test") == "clean") & (!isTRUE(convert))) x | |
if (isTRUE(convert)) out <- type.convert(out, as.is = TRUE) | |
if (isTRUE(relist)) { | |
out <- split(out, factor(rep.int(seq.int(length(x)), lengths(x)))) | |
if (is.null(names(x))) unname(out) else `names<-`(out, names(x)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dt1 <- fread("V1 V2 V3 | |
x b;c;d 1 | |
y d;ef 2 | |
z d;ef 3 | |
m tmp 4 | |
n tmp 5 | |
n x;yz 5") | |
dt1[4, V2:=''] # this record will be lost because V2 value is empty string | |
dt1[5, V2:=NA_character_] # NA value is processed correctly |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Should be faster than the other option here, hopefully with not too much overhead compared to `melt` | |
NA_type <- function(string) { | |
switch(string, | |
double = NA_real_, | |
integer = NA_integer_, | |
complex = NA_complex_, | |
character = NA_character_, | |
NA) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<style> | |
video { | |
width: 100%; | |
height: auto; | |
} | |
</style> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Function to draw observations from stratified norm sample | |
#' | |
#' This function creates a stratified random sample, given an arbitrary number of | |
#' factors and levels within those factors. | |
#' | |
#' @param dat data.frame object | |
#' @param strata character; a named vector indicating the strata variables | |
#' @param observations numeric; number of cases to sample from each strata | |
#' @param return.grid logical; return grid of factor combintions? | |
#' @param full.data logical; return the original dataset with a new logical |