ss_count | R Documentation |
Computes the number of conditions (provided as a character vectorcond
),
involving the input variables vars
, that were found to be TRUE
.
Options available to exclude certain values from the input variables
(provided as a character vector exclude
).
ss_count(
data,
name,
vars,
vars_temp = NULL,
exclude = NULL,
combine = FALSE,
allow_missingness = TRUE,
cond
)
data |
tbl. Data frame containing the columns to be summarized. |
name |
character. The name of the summary score. |
vars |
character vector. The name(s) of the column(s) to be summarized. |
vars_temp |
character vector. The name(s) of temporary column(s) used
to compute the summary score. Note, these columns are not checked for
missingness. See |
exclude |
character (vector). The value(s) to be excluded (Default: NULL; all values are used). |
combine |
logical. Whether to combine the summary score column with the input data frame (Default: FALSE). |
allow_missingness |
logical. Default set to TRUE. If TRUE, summary score
is set to |
cond |
character vector. Each specified condition, involving the values
of specific input fields, gets tested for |
tbl. The input data frame with the summary score appended as a new column.
dat <- tibble::tibble(
id = c("1", "2", "3", "4", "5", "6", "7", "8"),
a_1 = c(1, 1, NA, 1, 1, 1, 1, 1),
a_2 = c(1, NA, NA, 1, 1, NA, 1, 1),
b_1 = c(1, 1, NA, NA, 1, 1, 1, 1),
b_2 = c(1, 1, NA, 1, 1, NA, 1, 1),
c = c(NA, 1, NA, 1, 777, 0, 1, 0)
)
# define conditions to assess
conditions <- c(
"a_1 == 1 & a_2 == 1",
"b_1 == 1 & b_2 == 1",
"c"
)
# count number of matched conditions
ss_count(
data = dat,
name = "ss",
vars = c("a_1", "a_2", "b_1", "b_2", "c"),
cond = conditions,
combine = TRUE
)
ss_count(
data = dat,
name = "ss",
vars = c("a_1", "a_2", "b_1", "b_2", "c"),
cond = conditions,
exclude = c("777"),
combine = TRUE
)
conditions <- paste(
c(
"a_1 == 1 & a_2 == 1",
"b_1 == 1 & b_2 == 1",
"c >= 1"
),
collapse = "&"
)
ss_count(
data = dat,
name = "ss",
vars = c("a_1", "a_2", "b_1", "b_2", "c"),
cond = conditions,
exclude = c("777"),
combine = TRUE
)
ss_count(
data = dat,
name = "ss",
vars = c("a_1", "a_2", "b_1", "b_2", "c"),
cond = conditions,
exclude = c("777"),
allow_missingness = FALSE,
combine = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.