View cSplit_e.R
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"))) {
View trim_ws.R
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))
View cSplit_fread_tests.R
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
View SO48607092.R
library(tidyverse)
library(data.table)
library(microbenchmark)
set.seed(1)
s <- sample(5, 10000, TRUE)
Sample <- rep(seq_along(s), s)
df <- data.frame(Sample,
motif = sample(LETTERS[1:10], length(Sample), TRUE),
chromosome = sample(2, length(Sample), TRUE))
View html5-video-presentation.html
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<style>
video {
width: 100%;
height: auto;
}
</style>
</head>
View SO43350554.R
# https://stackoverflow.com/questions/43350554/r-filling-in-empty-variables
fun1 <- function() {
apply(t(df), 2, function(x) {
conds <- rowSums(cbind(x, dplyr::lag(x), dplyr::lead(x)), na.rm = T)==2
x[conds] <- 1
x
}) %>% t()
}
View keybase.md

Keybase proof

I hereby claim:

  • I am mrdwab on github.
  • I am anandakpec (https://keybase.io/anandakpec) on keybase.
  • I have a public key whose fingerprint is DA48 E710 3EDA 383B F911 85F4 95AD 8366 3CB7 5B67

To claim this, I am signing this object:

View server.R
# server.R
library(shiny)
shinyServer(function(input, output) {
## Start by creating a reactive version of the dataset listing. This
## will then let us access the data for use in dynamically creating
## the listing of the available datasets. We only need the "id"
## and "title" datasets.
View kobo_time_parser.R
kobo_time_parser_UTC <- function(instring) {
tmp <- gsub("\\.\\d{3}|:", "", instring)
tmp <- chartr(" ", "0", format(tmp, justify = "left", width = 22))
as.POSIXct(strptime(tmp, format = "%Y-%m-%dT%H%M%S%z", tz = "UTC"))
}
kobo_time_parser <- function(indatetime, timezone = Sys.timezone()) {
format(kobo_time_parser_UTC(indatetime), tz = timezone, usetz = TRUE)
}
View stratified.R
## Helper functions. Won't bother exporting.
dt_check <- function(indt) {
if (!is.data.table(indt)) as.data.table(indt) else indt
}
g_s <- function(indt, group) indt[, .N, by = group]
g_n <- function(indt, group, size) indt[, list(ss = size), by = group]
g_f <- function(indt, group, size) indt[, list(ss = ceiling(.N * size)), by = group]
g_l <- function(indt, group, size) setnames(data.table(names(size), unname(size)), c(group, "ss"))[]
g_sel <- function(indt, select) {
if (is.null(names(select))) {