Skip to content

Commit

Permalink
Merge pull request #24 from gbganalyst/input-checking
Browse files Browse the repository at this point in the history
updated the fill_missing_values() roxygen file
  • Loading branch information
gbganalyst authored Apr 25, 2024
2 parents 8ab3136 + 11c5073 commit 2fa04fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
25 changes: 12 additions & 13 deletions R/fill_missing_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#'
#' @param df A dataframe to process for missing value imputation.
#'
#' @param selected_variables An optional vector of variable names within `df
#' @param selected_variables An optional vector of variable names within `df`
#' for which missing values should be imputed. If `NULL` (default), imputation
#' is applied to all variables in the data frame. Variables must be quoted.
#'
#' @param method A character string specifying the imputation method for
#' continuous variables. Supported methods are "min", "max", "mean", "median",
#' "harmonic", and "geometric". The default method is "mean". For categorical
#' variables, the mode is always used.
#' continuous variables. Supported methods are `"min"`, `"max"`, `"mean"`,
#' `"median"`, `"harmonic"`, and `"geometric"`. The default method is `"mean"`.
#' For categorical variables, the `mode` is always used.
#'
#' @return A data frame with missing values imputed according to the specified
#' `method`.
Expand Down Expand Up @@ -96,15 +96,14 @@ fill_missing_values <- function(df, selected_variables = NULL, method = c("mean"
} # Skip non-numeric columns

replacement_value <- switch(method,
min = min(x, na.rm = TRUE),
max = max(x, na.rm = TRUE),
mean = mean(x, na.rm = TRUE),
median = median(x, na.rm = TRUE),
harmonic = harmonic_mean(x),
geometric = geometric_mean(x),
x
) # Default to return x as is

min = min(x, na.rm = TRUE),
max = max(x, na.rm = TRUE),
mean = mean(x, na.rm = TRUE),
median = median(x, na.rm = TRUE),
harmonic = harmonic_mean(x),
geometric = geometric_mean(x),
x # Default to return x as is
)

# Explicitly cast the replacement value to the same type as x

Expand Down
9 changes: 5 additions & 4 deletions man/fill_missing_values.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2fa04fc

Please sign in to comment.