scale_matrix_rows: row wise z-score scaling of matrix

Description Usage Arguments Details Value Examples

View source: R/p99_matrix_scaling_functions.R

Description

This function is similar to the base::scale() function. This function is copied from the tutorial posted by user strictlystat on R-Bloggers. Reference: https://www.r-bloggers.com/a-faster-scale-function/

Usage

1
2
3
4
5
6
7
8
scale_matrix_rows(
  x,
  center = TRUE,
  scale = TRUE,
  add_attr = TRUE,
  rows = NULL,
  cols = NULL
)

Arguments

x

A matrix

center

Logical: whether to center each row by row mean or not. Default: TRUE

scale

Logical: scale each row by standard deviation or not. Default: TRUE

add_attr

Logical: whether to add attributes to scalled matrix. Default: FALSE

rows

Row indices if only a subset of rows need to be used. Default: NULL i.e. all rows are used

cols

Column indices if only a subset of columns needs to be used. Default: NULL i.e. all columns are used

Details

IMP: Remember that default base::scale() function has different behaviour when center == FALSE. If center is TRUE, the scaling is done by dividing centered columns of x by standard deviation. If center is FALSE, the root mean square of column. Refer to scale for details.

Value

A row scaled matrix

Examples

1

lakhanp1/chipmine documentation built on March 6, 2021, 9:06 a.m.