Learn R Programming

wordspace (version 0.2-0)

scaleMargins: Scale Rows and/or Columns of a Matrix (wordspace)

Description

This function provides a fast and memory-efficient way to scale the rows and/or columns of a dense or sparse matrix. Each row is multiplied with the corresponding element of the vector rows, each column with the corresponding element of the vector cols.

Usage

scaleMargins(M, rows=NULL, cols=NULL, duplicate=TRUE)

Arguments

M

a dense or sparse matrix in canonical format

rows

a numeric vector with length equal to the number of rows of M, or a single number. If missing or NULL, the rows of M are not rescaled.

cols

a numeric vector with length equal to the number of columns of M, or a single number. If missing or NULL, the columns of M are not rescaled.

duplicate

if FALSE, modify the matrix M in place. Don't ever set this argument to FALSE.

Value

The rescaled dense or sparse matrix.

Details

If M is not in canonical format (dense numeric matrix or sparse matrix of class dgCMatrix), it will automatically be converted. In this case, the precise behaviour of duplicate=FALSE is undefined.

duplicate=FALSE is intended for internal use only.

See Also

dsm.is.canonical

Examples

Run this code
# NOT RUN {
M <- matrix(1, 5, 3)
scaleMargins(M, rows=1:5, cols=c(1, 10, 100))

# }

Run the code above in your browser using DataLab