Usage
s_count_values(
x,
values,
na.rm = TRUE,
.N_col,
.N_row,
denom = c("n", "N_row", "N_col")
)
# S3 method for character
s_count_values(x, values = "Y", na.rm = TRUE, ...)
# S3 method for factor
s_count_values(x, values = "Y", ...)
# S3 method for logical
s_count_values(x, values = TRUE, ...)
count_values(
lyt,
vars,
values,
...,
table_names = vars,
.stats = "count_fraction",
.formats = NULL,
.labels = c(count_fraction = paste(values, collapse = ", ")),
.indent_mods = NULL
)
a_count_values(
x,
values,
na.rm = TRUE,
.N_col,
.N_row,
denom = c("n", "N_row", "N_col")
)Arguments
- x
(
numeric)
vector of numbers we want to analyze.- values
(
character)
specific values that should be counted.- na.rm
(
flag)
whetherNAvalues should be removed fromxprior to analysis.- .N_col
(
count)
row-wise N (row group count) for the group of observations being analyzed (i.e. with no column-based subsetting) that is passed byrtables.- .N_row
(
count)
column-wise N (column count) for the full column that is passed byrtables.- denom
(
string)
choice of denominator for proportion:
can ben(number of values in this row and column intersection),N_row(total number of values in this row across columns), orN_col(total number of values in this column across rows).- ...
additional arguments for the lower level functions.
- lyt
(
layout)
input layout where analyses will be added to.- vars
(
character)
variable names for the primary analysis variable to be iterated over.- table_names
(
character)
this can be customized in case that the samevarsare analyzed multiple times, to avoid warnings fromrtables.- .stats
(
character)
statistics to select for the table.- .formats
(named
characterorlist)
formats for the statistics.- .labels
(named
character)
labels for the statistics (without indent).- .indent_mods
(named
integer)
indent modifiers for the labels.
Value
See s_summary.logical() for the returned statistics, as this is used inside.
Functions
s_count_values(): Statistics Function which is a generic function to count values.s_count_values(character): Method forcharactervectorsx.s_count_values(factor): method forfactorvectorsx. This checks whethervaluesare all included in the levels ofxand fails otherwise. It then proceeds by converting tocharacterand callings_count_values.character.s_count_values(logical): method forlogicalvectorsx.count_values(): Analyze Function which adds the counting analysis to the input layout. Note that additional formatting arguments can be used here.a_count_values(): Formatted Analysis function which can be further customized by callingrtables::make_afun()on it. It is used asafuninrtables::analyze().
Note
Variable labels are shown when there is more than one element in vars, otherwise they
are hidden.
Examples
# `s_count_values.character`
s_count_values(x = c("a", "b", "a"), values = "a")
#> $n
#> [1] 3
#>
#> $count
#> [1] 2
#>
#> $count_fraction
#> [1] 2.0000000 0.6666667
#>
#> $n_blq
#> [1] 0
#>
s_count_values(x = c("a", "b", "a", NA, NA), values = "b", na.rm = FALSE)
#> $n
#> [1] 5
#>
#> $count
#> [1] 1
#>
#> $count_fraction
#> [1] 1.0 0.2
#>
#> $n_blq
#> [1] 0
#>
# `s_count_values.factor`
s_count_values(x = factor(c("a", "b", "a")), values = "a")
#> $n
#> [1] 3
#>
#> $count
#> [1] 2
#>
#> $count_fraction
#> [1] 2.0000000 0.6666667
#>
#> $n_blq
#> [1] 0
#>
# `s_count_values.logical`
s_count_values(x = c(TRUE, FALSE, TRUE))
#> $n
#> [1] 3
#>
#> $count
#> [1] 2
#>
#> $count_fraction
#> [1] 2.0000000 0.6666667
#>
#> $n_blq
#> [1] 0
#>
# `count_values`
basic_table() %>%
count_values("Species", values = "setosa") %>%
build_table(iris)
#> all obs
#> ————————————————————
#> setosa 50 (33.33%)
# `a_count_values`
a_count_values(x = factor(c("a", "b", "a")), values = "a", .N_col = 10, .N_row = 10)
#> RowsVerticalSection (in_rows) object print method:
#> ----------------------------
#> row_name formatted_cell indent_mod row_label
#> 1 n 3 0 n
#> 2 count 2 0 count
#> 3 count_fraction 2 (66.67%) 0 count_fraction
#> 4 n_blq 0 0 n_blq