update_record: Update Rows in a Data Frame Based on a Condition

View source: R/update.R

update_recordR Documentation

Update Rows in a Data Frame Based on a Condition

Description

Modifies the values in a specified column of a data frame for rows that meet a given condition.

Usage

update_record(.data, column = NULL, where = NULL, set_to = NULL, ...)

Arguments

.data

A data frame. The dataset to modify.

column

A column in the data frame to update. Can be specified as a column name, index, or unquoted column symbol.

where

A condition that determines which rows to update. Must evaluate to a logical vector of the same length as the number of rows in '.data'.

set_to

The value to assign to the rows in the specified column where the 'where' condition is 'TRUE'.

...

Additional arguments (currently unused, reserved for future use).

Details

This function updates values in a specified column of a data frame for rows that satisfy the given condition. The 'column' parameter can be provided as: - A numeric column index (e.g., '2'). - A column name (e.g., '"value"'). - An unquoted column symbol (e.g., 'value').

Value

The modified data frame with updated values.

Examples

# Example data frame
df <- data.frame(
  id = 1:5,
  value = c(10, 20, 30, 40, 50)
)

# Update rows where id > 3
updated_df <- update_record(df, column = value, where = id > 3, set_to = 100)
print(updated_df)

# Using column as a string
updated_df <- update_record(df, column = "value", where = id == 2, set_to = 99)
print(updated_df)


matriz documentation built on April 3, 2025, 7:22 p.m.