This function replaces values in multiple columns of a target dataframe with values from a source dataframe based on a matching key. The function takes two dataframes, a key column, and a vector of columns to be updated, and returns the updated target dataframe.

replace_values_by_key(target_df, source_df, key, columns_to_update)

Arguments

target_df

A dataframe containing the original values.

source_df

A dataframe containing the new values to replace in the target dataframe.

key

The column name (as a string) that is used as the key for matching rows in both dataframes.

columns_to_update

A character vector of column names in target_df whose values will be replaced.

Value

A dataframe with the specified columns' values updated based on the matching key.