Learn R Programming

ribiosUtils (version 1.7.7)

rowscale.matrix: Scale a matrix by row

Description

Scaling a matrix by row can be slightly slower due to a transposing step.

Usage

# S3 method for matrix
rowscale(x, center = TRUE, scale = TRUE)

Value

A matrix with each row scaled.

Arguments

x

An matrix

center

Logical, passed to scale. to TRUE

scale

Logical, passed to scale. TRUE

Author

Jitao David Zhang <jitao_david.zhang@roche.com>

See Also

Examples

Run this code

mat <- matrix(rnorm(20), nrow=4)
rs.mat <- rowscale(mat)

print(mat)
print(rs.mat)
rowMeans(rs.mat)
apply(rs.mat, 1L, sd)

rowscale(mat, center=FALSE, scale=FALSE) ## equal to mat
rowscale(mat, center=TRUE, scale=FALSE)
rowscale(mat, center=FALSE, scale=TRUE)

Run the code above in your browser using DataLab