grbase-utilities: gRbase utilities

Description Usage Arguments Details Author(s) Examples

Description

Various utility functions for gRbase. Includes 'faster versions' of certain standard R functions.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Arguments

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

Details

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])'

Author(s)

Søren Højsgaard, sorenh@math.aau.dk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## 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]))
}

DataSciBurgoon/gRbase documentation built on March 25, 2020, 12:03 a.m.