This file contains 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 <- function(indt, splitCols, sep = ",", direction = "wide", | |
makeEqual = NULL, fixed = TRUE, drop = TRUE, | |
stripWhite = FALSE) { | |
message("`cSplit` is now part of the 'splitstackshape' package (V1.4.0)") | |
## requires data.table >= 1.8.11 | |
require(data.table) | |
if (!is.data.table(indt)) setDT(indt) | |
if (is.numeric(splitCols)) splitCols <- names(indt)[splitCols] | |
if (any(!vapply(indt[, splitCols, with = FALSE], | |
is.character, logical(1L)))) { |
This file contains 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
stratified <- function(df, group, size, select = NULL, | |
replace = FALSE, bothSets = FALSE) { | |
if (is.null(select)) { | |
df <- df | |
} else { | |
if (is.null(names(select))) stop("'select' must be a named list") | |
if (!all(names(select) %in% names(df))) | |
stop("Please verify your 'select' argument") | |
temp <- sapply(names(select), | |
function(x) df[[x]] %in% select[[x]]) |
This file contains 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
@echo off | |
if [%1]==[] goto :eof | |
:loop | |
pdftk %1 stamp back.pdf output "%~dpn1_new%~x1" owner_pw somepasswordyouwant | |
shift | |
if not [%1]==[] goto loop |
This file contains 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
############################################################################### | |
# Sample Size and Confidence Interval Calculation # | |
# v 1.3 by "Ananda Mahto"/mrdwab/ananda@mahto.info # | |
# 2011 May 17 # | |
# --------------------------------------------------------------------------- # | |
# # | |
# Example usage: # | |
# * sample.size.table(c.lev = c(90, 95, 98, 99), population = 378) # | |
# * sample.size(c.lev = 98, population = 200) # | |
# * confidence.interval(c.lev = 95, p.ss = 80, population = 100) # |
This file contains 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
REM ***** BASIC ***** | |
Function CELL_NOTE(vSheet,lRowIndex&,iColIndex%) | |
Dim v | |
v = getSheetCell(vSheet,lRowIndex&,iColIndex%) | |
if vartype(v) = 9 then | |
CELL_NOTE = v.Annotation.getText.getString | |
else | |
CELL_NOTE = v | |
endif | |
End Function |
This file contains 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
LinearizeNestedList <- function(NList, LinearizeDataFrames=FALSE, | |
NameSep="/", ForceNames=FALSE) { | |
# LinearizeNestedList: | |
# | |
# https://sites.google.com/site/akhilsbehl/geekspace/ | |
# articles/r/linearize_nested_lists_in_r | |
# | |
# Akhil S Bhel | |
# | |
# Implements a recursive algorithm to linearize nested lists upto any |
This file contains 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
upper_left <- function(n, diag = TRUE, byrow = FALSE) { | |
x <- seq.int(n) | |
tmp1 <- sequence(rev(x)) | |
tmp2 <- rep(x, rev(x)) | |
out <- if (byrow) { | |
cbind(row = tmp2, col = tmp1) | |
} else { | |
cbind(row = tmp1, col = tmp2) | |
} | |
if (diag) out else out[rowSums(out) != n + 1, ] |
This file contains 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
fun_for <- function(x, target, n) { | |
if (!n %in% c(2, 3)) stop("The accounting Elves are crazy!") | |
if (n == 2) { | |
out <- x[(target - x) %in% x] | |
} else if (n == 3) { | |
out <- numeric(0) | |
for (i in seq_along(x)) { | |
s1 <- x + x[i] | |
for (j in seq_along(s1)) { | |
s2 <- s1 + x[j] |
This file contains 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
# Using `fread` and `fwrite` to paste together columns like `do.call(paste, ...)` | |
fpaste <- function(dt, sep = ",") { | |
x <- tempfile() | |
if (sep == "") { | |
data.table(V1 = do.call(stringi::stri_join, c(dt, sep = ""))) | |
} else { | |
fwrite(dt, file = x, sep = sep, col.names = FALSE) | |
fread(x, sep = "\n", header = FALSE) | |
} | |
} |
This file contains 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
## If your replacement is just a sequence of integers the length of the unique values being factored, | |
## you can create a function like this which should be quite fast. | |
fac2int <- function(x, levels, labels = levels, exclude = NA, ordered = is.ordered(x), nmax = NA) { | |
as.integer(factor(x, levels, labels, exclude, ordered, nmax)) | |
} | |
### DIFFERENT APPROACHES TO TEST | |
fun_datamatrix <- function() { | |
df[] <- data.matrix(as.data.frame(lapply(df, factor, levels = df2$Group))) |
NewerOlder