| mutate_qc | R Documentation |
mutate_qc and transmute_qc return identical objects as
dplyr::mutate and dplyr::transmute. Like dplyr, mutate_qc
adds new variables and preserves existing variables, and transmute_qc
drops existing variables.
mutate_qc(.data, ..., .group_check = F)
transmute_qc(.data, ..., .group_check = F)
.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. |
... |
< The value can be:
|
.group_check |
a logical value, that when TRUE, will print a table with each group variable, and columns called "var_name" and "n_missing" that together indicate, for each group, how many values are missing of newly created variables. Only variables that contain at least 1 missing value are reported. 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. |
mutate_qc and transmute_qc are used exactly the same as
mutate and transmute 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 or edited variable(s).
An object of the same class as .data. This object will be
identical to that which is returned when running dplyr::mutate or
dplyr::transmute functions.
There are _qc versions of the scoped mutate functions. See
mutate_at_qc, mutate_all_qc, or
mutate_if_qc. Or transmute_at_qc,
transmute_all_qc, or transmute_if_qc.
All functions work with grouped data.
mutate
practice_data <-
data.frame(
A = c(1:4, NA),
B = c(NA, 7:10),
C = 21:25,
G = c("X", "X", "X", "Y", "Y"),
stringsAsFactors = F
)
# Use the _qc versions just like normal dplyr mutate functions
mutate_qc(practice_data, new_var_1 = A + B, new_var_2 = A - C)
# mutate_qc will only report the number of NAs and INFs in the final copy of
# the variable, so if you mutate the same variable more thna once in the
# call, it's only the final outcome that gets tracked
mutate_qc(practice_data, new_var = A + B, new_var = C + 1)
# Functions worked on grouped data, too
grouped_data <- dplyr::group_by(practice_data, G)
mutate_qc(grouped_data, new_var_1 = A + mean(B), mean_b = mean(B))
# Setting .group_check = T will also print a table indicating which groups
# have a missing value, on what variable, and how many values are missing.
mutate_qc(grouped_data, new_var_1 = A + mean(B), mean_b = mean(B), .group_check = T)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.