R/impute.R

Defines functions impute

Documented in impute

impute <- function(x, what=c("median", "mean")){

    what <- match.arg(what)
    
    if(what == "median"){
        retval <-
            apply(x, 2,
                  function(z) {z[is.na(z)] <- median(z, na.rm=TRUE); z})
    }
    else if(what == "mean"){
        retval <-
            apply(x, 2,
                  function(z) {z[is.na(z)] <- mean(z, na.rm=TRUE); z})
    }
    retval
}

Try the e1071 package in your browser

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

e1071 documentation built on Feb. 16, 2023, 8:31 p.m.