check_above: Replace repeated values with a replacement string

View source: R/check_above.R

check_aboveR Documentation

Replace repeated values with a replacement string

Description

This function checks whether each element in a vector x is the same as the element directly above it (i.e., the previous value in the vector). If so, it replaces that element with a specified replacement value.

Usage

check_above(x, replacement = "")

Arguments

x

A vector (typically character or factor) to check for repeated consecutive values.

replacement

A value (default is "") to replace repeated values with.

Details

This is often useful for visual display in tables, where repeated values in consecutive rows can be suppressed for readability.

Value

A character vector where values that are the same as the previous value are replaced with replacement. The first element is always retained.

Examples

check_above(c("A", "A", "B", "B", "B", "C"))
# Returns: "A" "" "B" "" "" "C"


emilelatour/lamisc documentation built on March 29, 2025, 1:23 p.m.