drop_if_all_na: Drop rows if all values on selected columns are missing

View source: R/wrangling-utils.R

drop_if_all_naR Documentation

Drop rows if all values on selected columns are missing

Description

Remove a row if all values on selected columns, or by default, on all columns, are missing, i.e. have values of NA or NaN.

Usage

drop_if_all_na(data, ...)

Arguments

data

A data frame

...

<tidy-select> Columns to inspect for missing values. If empty, all columns are used.

Details

The drop_na function will remove any row if it has any NA in selected columns. By default, it will remove the row there is any NA or NaN in any column. This drop_if_all_na function is similar but removes the row only if all values in the selected columns are NA or NaN. As with drop_na, by default it will use all columns. In other words, by default, drop_if_all_na removes any row if all values on that row are NA or NaN.

Value

A data frame, possibly with some rows dropped.

Examples

data_df <- data.frame(x = c(1, 2, NA, NA), y = c(2, NA, 5, NA))

drop_if_all_na(data_df)
drop_if_all_na(data_df, x)
drop_if_all_na(data_df, y)
drop_if_all_na(data_df, x, y)
drop_if_all_na(data_df, x:y)
drop_if_all_na(data_df, starts_with('x'), ends_with('y'))


mark-andrews/psyntur documentation built on Nov. 18, 2024, 7:17 a.m.