Learn R Programming

gRbase (version 1.8-4.5)

gRbase_utilities: gRbase utilities

Description

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

Usage

rhsFormula2list(f)

rhsf2list(f)

list2rhsFormula(f)

list2rhsf(f)

rowmat2list(XX_)

colmat2list(XX_)

matrix2list(XX_, byrow = TRUE)

which.arr.index(XX_)

which_matrix_index(XX_)

rowSumsPrim(XX_)

colSumsPrim(XX_)

colwiseProd(v, M)

Arguments

f

Formula specification (a right-hand sided formula, a numeric/character vector or a list of vectors).

XX_

A matrix.

byrow

Should the split be by row or by column.

v

A vector.

M

A matrix.

Details

which.arr.ind: Returns matrix n x 2 matrix with indices of non-zero entries in matrix XX_. Notice which_matrix_index__ is cpp implementation.

colwiseProd: multiplies a vector v and a matrix M columnwise (as opposed to rowwise which is achieved by v * M). Hence colwiseProd does the same as t(v * t(M)) - but it does so faster for numeric values.

Examples

Run this code
# NOT RUN {
## colwiseProd
M <- matrix(1:16, nrow=4)
v <- 1:4
t(v * t(M))
colwiseProd(v, M)
# }
# NOT RUN {
system.time(for (ii in 1:100000)  t(v * t(M)))
system.time(for (ii in 1:100000)  colwiseProd(v, M))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab