This function imputes mode The function can impute mode for all columns or for a selected set of columns.

impute_mode(df, variables = colnames(df))

Arguments

df

A data frame containing the data to impute.

variables

A character vector containing the names of the columns to impute using mode. The default value is a list containing all column names of `df`.

Value

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

Examples

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