Takes two variables with different missings and gives one variable with values of the second variable substituted where the first had missings.

aggregate2sources(df, new_var = NULL, var1 = NULL, var2 = NULL,
  remove_old_variables = TRUE, overwrite = FALSE)

Arguments

df

data.frame or variable

new_var

new variable name

var1

first source. Assumed to be new_var.x (default suffixes after merging)

var2

second source. Assumed to be new_var.y (default suffixes after merging)

remove_old_variables

Defaults to not keeping var1 and var2 in the resulting df.

overwrite

Whether to overwrite a new_var that already exists. Defaults to false.

Examples

cars$dist.x = cars$dist cars$dist.y = cars$dist cars$dist.y[2:5] = NA cars$dist.x[10:15] = NA # sprinkle missings cars$dist = NULL # remove old variable cars = aggregate2sources(cars, 'dist')
#> 6 fewer missings