Skip to contents

Cap matrix values at specified minimum and/or maximum. Requires matrix to be active.

Usage

clip_values(.data, min = NULL, max = NULL)

Arguments

.data

A tidymatrix object with matrix active

min

Minimum value (values below are set to this)

max

Maximum value (values above are set to this)

Value

A tidymatrix object with clipped matrix values

Examples

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

# Clip to [-2, 2] range
tm_clipped <- tm |>
  activate(matrix) |>
  clip_values(min = -2, max = 2)

# Only set floor
tm_floor <- tm |>
  activate(matrix) |>
  clip_values(min = 0)