d_where: Apply a boolean mask to a delayed matrix

View source: R/delarr-verbs.R

d_whereR Documentation

Apply a boolean mask to a delayed matrix

Description

Elements failing the predicate are replaced with fill at materialisation time.

Usage

d_where(x, predicate, fill = 0)

Arguments

x

A delarr.

predicate

A function or formula returning a logical matrix.

fill

Replacement value for elements where the predicate is FALSE.

Value

A delarr including the mask.

Examples

mat <- matrix(c(-1, 2, -3, 4, -5, 6), nrow = 2, ncol = 3)
darr <- delarr(mat)

# Replace negative values with 0
masked <- darr |> d_where(~ .x >= 0, fill = 0) |> collect()
masked

# Replace values below threshold with NA
filtered <- darr |> d_where(~ .x > 1, fill = NA) |> collect()
filtered

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