From 11c507397573f9c485a0ef1aca462a36235332ef Mon Sep 17 00:00:00 2001 From: gbganalyst Date: Thu, 25 Apr 2024 09:41:14 +0100 Subject: [PATCH] updated the fill_missing_values() roxygen file --- R/fill_missing_values.R | 25 ++++++++++++------------- man/fill_missing_values.Rd | 9 +++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/R/fill_missing_values.R b/R/fill_missing_values.R index 78fa071..77e4ee3 100644 --- a/R/fill_missing_values.R +++ b/R/fill_missing_values.R @@ -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`. @@ -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 diff --git a/man/fill_missing_values.Rd b/man/fill_missing_values.Rd index 3f5a99a..09656e7 100644 --- a/man/fill_missing_values.Rd +++ b/man/fill_missing_values.Rd @@ -13,13 +13,14 @@ fill_missing_values( \arguments{ \item{df}{A dataframe to process for missing value imputation.} -\item{selected_variables}{An optional vector of variable names within \verb{df for which missing values should be imputed. If }NULL` (default), imputation +\item{selected_variables}{An optional vector of variable names within \code{df} +for which missing values should be imputed. If \code{NULL} (default), imputation is applied to all variables in the data frame. Variables must be quoted.} \item{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 \code{"min"}, \code{"max"}, \code{"mean"}, +\code{"median"}, \code{"harmonic"}, and \code{"geometric"}. The default method is \code{"mean"}. +For categorical variables, the \code{mode} is always used.} } \value{ A data frame with missing values imputed according to the specified