grbase-utilities | R Documentation |
Various utility functions for gRbase. Includes 'faster versions' of certain standard R functions.
rhsFormula2list(form)
rhsf2list(form)
rhsf2vec(form)
listify_dots(dots)
list2rhsFormula(form)
list2rhsf(form)
rowmat2list(X)
colmat2list(X)
matrix2list(X, byrow = TRUE)
which.arr.index(X)
which_matrix_index(X)
rowSumsPrim(X)
colSumsPrim(X)
colwiseProd(v, X)
lapplyV2I(setlist, item)
lapplyI2V(setlist, item)
form |
Formula specification (a right-hand sided formula, a numeric/character vector or a list of vectors). |
dots |
dot-arguments to be turned into a list |
X |
A matrix. |
byrow |
Should the split be by row or by column. |
v |
A vector. |
setlist |
A list of atomic vectors |
item |
An atomic vector |
which.arr.ind
: Returns matrix n x 2 matrix with
indices of non-zero entries in matrix X
. Notice
which_matrix_index__
is cpp implementation.
colwiseProd
: multiplies a vector v and a matrix X
columnwise (as opposed to rowwise which is achieved by
v * X
). Hence colwiseProd
does the same as
t(v * t(X))
- but it does so faster for numeric values.
lapplyV2I: same as but much faster than lapply(setlist, function(elt) match(elt, item))
lapplyI2V: same as but faster than lapply(setlist, function(elt) item[elt])
Søren Højsgaard, sorenh@math.aau.dk
## colwiseProd
X <- matrix(1:16, nrow=4)
v <- 1:4
t(v * t(X))
colwiseProd(v, X)
## Not run:
system.time(for (ii in 1:100000) t(v * t(X)))
system.time(for (ii in 1:100000) colwiseProd(v, X))
## End(Not run)
setlist <- list(c(1,2,3), c(2,3,4), c(2,4,5))
item <- c(2,3)
lapplyV2I(setlist, item)
lapply(setlist, function(gg) match(gg, item))
lapplyI2V(setlist, item)
lapply(setlist, function(x) item[x])
if (require(microbenchmark)){
microbenchmark(
lapplyV2I(setlist, item),
lapply(setlist, function(elt) match(elt, item)))
microbenchmark::microbenchmark(
lapplyI2V(setlist, item),
lapply(setlist, function(elt) item[elt]))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.