This function imputes missing data in a data frame using one or more specified methods. The function can impute missing data for all columns or for a selected set of columns.

impute_missing_data(df, variables = list(colnames(df)), methods = c("mean"))

Arguments

df

A data frame containing the data to impute.

variables

A list of character vectors specifying the columns to impute for each method. Each element of the list should be a character vector containing the names of the columns to impute using the corresponding method in the `methods` parameter. The default value is a list containing all column names of `df`.

methods

A character vector specifying the methods to use for imputing missing data. The available methods are `"mean"`, `"median"` and `"mode"`. The default value is `"mean"`.

Value

A data frame with the same dimensions as `df` where missing values have been imputed using the specified methods.

Examples

df <- data.frame(x <- c(1, NA, 3, NA),y <- c(NA, 4, 6, 8))
impute_missing_data(df)
#>   x....c.1..NA..3..NA. y....c.NA..4..6..8.
#> 1                    1                   6
#> 2                    2                   4
#> 3                    3                   6
#> 4                    2                   8