This function replaces NA values in a specified column of a data frame with corresponding values from another specified column. The function works like the 'coalesce' function in SQL, but it is designed to handle data frames.

replace_NA_with_y(data, var_with_NA, var_to_fill_NA)

Arguments

data

A data frame.

var_with_NA

A variable name within the data frame that contains missing values.

var_to_fill_NA

A variable name within the data frame that contains values to replace the missing values in var_with_NA.

Value

A data frame with the NA values in the var_with_NA variable replaced by the corresponding values in the var_to_fill_NA variable. The var_to_fill_NA variable is removed from the output.