Skip to contents

Perform z-score scaling (center and scale to unit variance) on the active dimension. Requires rows or columns to be active.

Usage

# S3 method for class 'tidymatrix'
scale(x, center = TRUE, scale = TRUE)

Arguments

x

A tidymatrix object with rows or columns active

center

If TRUE (default), center to mean = 0

scale

If TRUE (default), scale to sd = 1

Value

A tidymatrix object with scaled matrix

Examples

mat <- matrix(rnorm(20, mean = 10, sd = 5), nrow = 4, ncol = 5)
tm <- tidymatrix(mat)

# Scale rows (z-score per row)
tm_scaled <- tm |>
  activate(rows) |>
  scale()

# Scale columns
tm_scaled <- tm |>
  activate(columns) |>
  scale()

# Only center, don't scale
tm_centered <- tm |>
  activate(rows) |>
  scale(center = TRUE, scale = FALSE)