filter_qc: Report number of dropped cases when performing dplyr filter.

View source: R/filter_qc.R

filter_qcR Documentation

Report number of dropped cases when performing dplyr filter.

Description

filter_qc returns an identical object as dplyr::filter, except that it automatically prints the number of cases (i.e., rows) that do not meet the filter conditions and that were thus dropped.

Usage

filter_qc(.data, ..., .group_check = F)

Arguments

.data

A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details.

...

<data-masking> Expressions that return a logical value, and are defined in terms of the variables in .data. If multiple expressions are included, they are combined with the & operator. Only rows for which all conditions evaluate to TRUE are kept.

.group_check

a logical value, that when TRUE, will print a table with each group variable and columns called "n_rows_dropped" and "percent_dropped" that together indicate, for each group, how many row were dropped when performing filter. Default is FALSE, to avoid excess printing. If data is not grouped and .group_check = T, then an error is thrown.

Value

An object of the same class as .data. This object will be identical to that which is returned when running the standard dplyr::filter function.

Scoped variants

There are _qc versions of the scoped filter functions. See filter_at_qc, filter_all_qc, or filter_if_qc.

See Also

filter

Examples

practice_data <- 
  data.frame(
    A = 1:12, 
    B = 6:17, 
    C = 8:19, 
    G = c(rep(c("A", "B"), each = 6)),
    stringsAsFactors = F
  )

# Basic filtering
filter_qc(practice_data, A > 5)
filter_qc(practice_data, A > 5 & B > 8)

# With grouped data and setting .group_check = T, you can see how many rows
# were dropped per group. Note that this will print a large table if you have 
# a lot of groups.
grouped_data <- group_by(practice_data, G)
filter_qc(grouped_data, A > 3, .group_check = T)


adamMaier/reviewr documentation built on Nov. 5, 2023, 7:21 a.m.