na_omit_if_prop {naflex}R Documentation

Conditionally omit missing values (single condition)

Description

These set of functions remove missing values from x if the single, specified check is satisfied, and returns x unmodified otherwise. They are special cases of na_omit_if, which is the general case for specifying multiple checks.

Usage

na_omit_if_prop(x, prop = NULL, strict = FALSE)

na_omit_if_n(x, n = NULL)

na_omit_if_consec(x, consec = NULL)

na_omit_if_non_na(x, n_non = NULL)

Arguments

x

Vector to omit missing values in if checks pass.

prop

The maximum proportion (0 to 1) of missing values allowed.

strict

A logical (default FALSE) indicating if the proportion of missing values must be strictly less than prop (strict = TRUE) or only less than prop (strict = FALSE).

n

The maximum number of missing values allowed.

consec

The maximum number of consecutive missing values allowed.

n_non

The minimum number of non-missing values required.

Details

These functions replicate the functionality of na_omit_if as individual functions for single checks.

For example, na_omit_if_consec(x, 4) is equivalent to na_omit_if(x, consec = 4).

This more restricted form may be desirable when only a single check is required.

Value

A vector of the same type as x. Either x with missing values removed if all checks pass, or x unmodified if any checks fail.

For consistency with na.omit, if missing values are removed, the indices of the removed values form an na.action attribute of class omit in the result.

If missing values are not removed (because the checks failed or there were no missing values in x) then no na.action attribute is added.


[Package naflex version 0.1.0 Index]