dropAllMissing: Handle Missing Values in Data

View source: R/dropAllMissing.R

dropAllMissingR Documentation

Handle Missing Values in Data

Description

This function is useful for dealing with NAs in data frames. Only rows in the data specified by columns that have only missing values are removed.

Usage

dropAllMissing(data, columns = "All", ...)

Arguments

data

the dataset to subset for all missing values.

columns

the columns to check for missing values. See Details.

...

any additional arguments to columns if it is a funciton.

Details

The value for columns can be a character vector containing the name of the columns to check, or "All," which checks all columns. Or it can be a function that returns a logical value–TRUE checks the column and FALSE does not. Any additonal arguments the the function can be given by ....

Value

The dataset data having rows with at least one nonmissing value in the columns specified by columns.

Examples

# create a short test dataset
test.df <- data.frame(A=c("a", "b", "c", "d", "e"),
   B=c(1, 2, NA, NA, 5), # numeric values
   C=c(1L, 3L, NA, 4L, NA), # integer values
   D=c(1, 2, NA, NA, 5)) # more numeric values
# The default, no row has all missing values
dropAllMissing(test.df)
# Check 2 columns
dropAllMissing(test.df, columns=c("B", "C"))
# check all numeric, including both integer and numeric types
dropAllMissing(test.df, columns=is.numeric)
# Check only those that are type numeric
dropAllMissing(test.df, columns=inherits, what="numeric")

USGS-R/restrend documentation built on Oct. 11, 2022, 6:10 a.m.