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))) {
View meltList.R
meltList <- function(inlist) {
require(data.table)
f <- function(l) {
names(l) <- seq_along(l)
lapply(l, function(x) {
x <- setNames(x, seq_along(x))
if(is.list(x)) f(x) else x
})
}
temp <- unlist(f(inlist))
View sortEnds.R
sortEnds <- function(invec, n, where = "head") {
invec <- switch(where, head = invec, tail = -invec,
stop("where must be 'head' or 'tail'"))
out <- sort(invec, partial = n)[seq_len(n)]
switch(where, head = out, tail = sort(-out))
}
View TabulateInt.R
TabulateInt <- function(vec) {
RANGE <- max(vec)
x <- c(1, RANGE)
if (any(vec <= 0)) {
x <- range(vec)
RANGE <- diff(x) + 1
vec <- vec + abs(min(x)) + 1
}
`names<-`(tabulate(vec, nbins = RANGE), x[1]:x[2])
}