summarize_all_qc: Scoped versions of summarize_qc

summarize_all_qcR Documentation

Scoped versions of summarize_qc

Description

summarize_all_qc, summarize_at_qc, and summarize_if_qc are used exactly the same as dplyr::summarize_all, dplyr::summarize_at, and dplyr::summarize_if, and require all of the same arguments and return identical objects. The only difference is that the _qc versions print a message indicating the number of NA or INFinite values created in the new summary variable(s). This is most useful when using on a grouped data frame.

Usage

summarize_all_qc(.tbl, .funs, ..., .group_check = F)

summarise_all_qc(.tbl, .funs, ..., .group_check = F)

summarize_at_qc(.tbl, .vars, .funs, ..., .cols = NULL, .group_check = F)

summarise_at_qc(.tbl, .vars, .funs, ..., .cols = NULL, .group_check = F)

summarize_if_qc(.tbl, .predicate, .funs, ..., .group_check = F)

summarise_if_qc(.tbl, .predicate, .funs, ..., .group_check = F)

Arguments

.tbl

A tbl object.

.funs

A function fun, a quosure style lambda ~ fun(.) or a list of either form.

...

Additional arguments for the function calls in .funs. These are evaluated only once, with tidy dots support.

.group_check

a logical value, that when TRUE, will print a table with each group variable and a column called "missing_vars" that lists which variables are missing from the summarized data for each group. Only groups with at least one missing variable are listed. This has no effect on the returned object, and only prints information. Default is FALSE, to avoid excess printing. If data is not grouped and .group_check = T, then an error is thrown.

.vars

A list of columns generated by vars(), a character vector of column names, a numeric vector of column positions, or NULL.

.cols

This argument has been renamed to .vars to fit dplyr's terminology and is deprecated.

.predicate

A predicate function to be applied to the columns or a logical vector. The variables for which .predicate is or returns TRUE are selected. This argument is passed to rlang::as_function() and thus supports quosure-style lambda functions and strings representing function names.

Value

An object of the same class as .data. This object will be identical to that which is returned when running the scoped variants of dplyr::summarize.

Grouping

All functions work with grouped data.

summarize vs. summarise

There are _qc versions of summarize and summarise. But this is America, use a z!

See Also

summarise_all

Examples

practice_data <- 
  data.frame(
  A = c(1:4, NA), 
  B = c(NA, 7:10), 
  C = 21:25,
  G = c(1, 1, 1, 2, 2)
)

# Use the _qc versions just like normal dplyr scoped summarize functions.
summarize_at_qc(
  practice_data, 
  vars(A, C), 
  funs(m = mean(., na.rm = T), s = sum)
)

summarize_all_qc(practice_data, funs(mean))

# Pipes work, just as they always do in dplyr
practice_data %>% summarize_if_qc(is.integer, mean)

# Functions work on grouped data, too
grouped_data <- group_by(practice_data, G)
grouped_data %>% 
  summarize_at_qc(vars(A, C), funs(m = mean(., na.rm = T), s = sum))

# Setting .group_check = T will print, for each group with a missing value,
# which new variables are missing. 
summarize_all_qc(grouped_data, mean, .group_check = T)


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