Learn R Programming

ribiosUtils (version 1.5-6)

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)

Arguments

x

An matrix

center

Logical, passed to scale. to TRUE

scale

Logical, passed to scale. TRUE

Value

A matrix with each row scaled.

See Also

scale

Examples

Run this code
# NOT RUN {
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