update_record | R Documentation |
Modifies the values in a specified column of a data frame for rows that meet a given condition.
update_record(.data, column = NULL, where = NULL, set_to = NULL, ...)
.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). |
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').
The modified data frame with updated values.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.