count_values_funs {tern} | R Documentation |
Count specific values
Description
We can count the occurrence of specific values in a variable of interest.
Usage
count_values(
lyt,
vars,
values,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = vars,
.stats = "count_fraction",
.formats = NULL,
.labels = c(count_fraction = paste(values, collapse = ", ")),
.indent_mods = NULL
)
s_count_values(
x,
values,
na.rm = TRUE,
.N_col,
.N_row,
denom = c("n", "N_row", "N_col")
)
## S3 method for class 'character'
s_count_values(x, values = "Y", na.rm = TRUE, ...)
## S3 method for class 'factor'
s_count_values(x, values = "Y", ...)
## S3 method for class 'logical'
s_count_values(x, values = TRUE, ...)
a_count_values(
x,
values,
na.rm = TRUE,
.N_col,
.N_row,
denom = c("n", "N_row", "N_col")
)
Arguments
lyt |
( |
vars |
( |
values |
( |
na_str |
( |
nested |
( |
... |
additional arguments for the lower level functions. |
table_names |
( |
.stats |
( |
.formats |
(named |
.labels |
(named |
.indent_mods |
(named |
x |
( |
na.rm |
( |
.N_col |
( |
.N_row |
( |
denom |
(
|
Value
-
count_values()
returns a layout object suitable for passing to further layouting functions, or tortables::build_table()
. Adding this function to anrtable
layout will add formatted rows containing the statistics froms_count_values()
to the table layout.
-
s_count_values()
returns output ofs_summary()
for specified values of a non-numeric variable.
-
a_count_values()
returns the corresponding list with formattedrtables::CellValue()
.
Functions
-
count_values()
: Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze()
. -
s_count_values()
: S3 generic function to count values. -
s_count_values(character)
: Method forcharacter
class. -
s_count_values(factor)
: Method forfactor
class. This makes an automatic conversion tocharacter
and then forwards to the method for characters. -
s_count_values(logical)
: Method forlogical
class. -
a_count_values()
: Formatted analysis function which is used asafun
incount_values()
.
Note
For
factor
variables,s_count_values
checks whethervalues
are all included in the levels ofx
and fails otherwise.For
count_values()
, variable labels are shown when there is more than one element invars
, otherwise they are hidden.
Examples
# `count_values`
basic_table() %>%
count_values("Species", values = "setosa") %>%
build_table(iris)
# `s_count_values.character`
s_count_values(x = c("a", "b", "a"), values = "a")
s_count_values(x = c("a", "b", "a", NA, NA), values = "b", na.rm = FALSE)
# `s_count_values.factor`
s_count_values(x = factor(c("a", "b", "a")), values = "a")
# `s_count_values.logical`
s_count_values(x = c(TRUE, FALSE, TRUE))
# `a_count_values`
a_count_values(x = factor(c("a", "b", "a")), values = "a", .N_col = 10, .N_row = 10)