Replace NULL Statistics with Specified Value
Source:R/replace_null_statistic.R
replace_null_statistic.Rd
When a statistical summary function errors, the "statistic"
column will be
NULL
. It is, however, sometimes useful to replace these values with a
non-NULL
value, e.g. NA
.
Arguments
- x
(
data.frame
)
an ARD data frame of class 'card'- value
(usually a
scalar
)
The value to replaceNULL
values with. Default isNA
.- rows
(
data-masking
)
Expression that return a logical value, and are defined in terms of the variables in.data
. Only rows for which the condition evaluates toTRUE
are replaced. Default isTRUE
, which applies to all rows.
Examples
# the quantile functions error because the input is character, while the median function returns NA
data.frame(x = rep_len(NA_character_, 10)) |>
ard_continuous(
variables = x,
statistic = ~ continuous_summary_fns(c("median", "p25", "p75"))
) |>
replace_null_statistic(rows = !is.null(error))
#> {cards} data frame: 3 x 8
#> variable context stat_name stat_label stat error
#> 1 x continuo… median Median NA
#> 2 x continuo… p25 Q1 NA non-nume…
#> 3 x continuo… p75 Q3 NA non-nume…
#> ℹ 2 more variables: fmt_fn, warning