R/remove_NA_data_frame.R

Defines functions remove_NA_data_frame

Documented in remove_NA_data_frame

## File Name: remove_NA_data_frame.R
## File Version: 0.09

remove_NA_data_frame <- function( formula, data, weights=NULL)
{
    #-- include weights
    N <- nrow(data)
    if ( is.null(weights) ){
        weights <- rep(1,N)
    }
    #--- remove missings
    data_vars <- stats::get_all_vars(formula=formula, data=data )
    ind <- which( rowMeans( 1 - is.na(data_vars) )==1 )
    data <- data[ ind, ]
    weights <- weights[ ind ]
    #--- output
    res <- list( data=data, weights=weights )
    return(res)
}

Try the mdmb package in your browser

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

mdmb documentation built on March 7, 2023, 6:58 p.m.