R/merge_imputed.R

Defines functions merge_imputed

Documented in merge_imputed

#' @title Merge imputed data and original dataset
#' @description Merge the imputed dataset from an  \code{imputeMulti} object with the original dataset. 
#' Merging is done by rownames, since imputeMulti maintains row-order during imputation.
#' @param impute_obj An object of class "imputeMulti".
#' @param y The dataset from which the missing data was imputed.
#' @param ... Arguments to be passed to other methods
#' @export
merge_imputed <- function(impute_obj, y, ...) {
  if (!is.imputeMulti(impute_obj)) stop("impute_obj must have class imputeMulti.")
  if (nrow(y) != nrow(impute_obj@data$imputed_data)) 
    stop("target and y do not have equal row counts.")
  
  x <- impute_obj@data$imputed_data
  x$rownames <- rownames(x)
  y$rownames <- rownames(y)
  return(merge(x, y, by= "rownames", ...))
}

Try the imputeMulti package in your browser

Any scripts or data that you put into this service are public.

imputeMulti documentation built on March 7, 2023, 8:37 p.m.