d_center: Center a delayed matrix along rows or columns

View source: R/delarr-verbs.R

d_centerR Documentation

Center a delayed matrix along rows or columns

Description

Center a delayed matrix along rows or columns

Usage

d_center(x, dim = c("rows", "cols"), axis = NULL, na.rm = FALSE)

Arguments

x

A delarr.

dim

Dimension along which to subtract the mean.

axis

Integer axis for N-d arrays (alternative to dim).

na.rm

Logical; remove missing values when computing the centre.

Value

A delarr with a deferred centering operation.

Examples

mat <- matrix(c(1, 2, 3, 10, 20, 30), nrow = 2, ncol = 3)
darr <- delarr(mat)

# Center rows (subtract row means)
centered_rows <- darr |> d_center(dim = "rows") |> collect()
centered_rows
rowMeans(centered_rows)  # Should be ~0

# Center columns (subtract column means)
centered_cols <- darr |> d_center(dim = "cols") |> collect()
colMeans(centered_cols)  # Should be ~0

delarr documentation built on July 1, 2026, 1:06 a.m.