collapse01: Collapse a group of binary variables (e.g. those generated by...

View source: R/collapse_01.R

collapse01R Documentation

Collapse a group of binary variables (e.g. those generated by checkbox variables in REDCap) into summary columns.

Description

Collapse a group of binary variables (e.g. those generated by checkbox variables in REDCap) into summary columns.

Usage

collapse01(
  df,
  cols,
  prefix = NULL,
  suffix = NULL,
  output = c("list", "yesno", "n"),
  remove = TRUE,
  binary0 = c(0, "0", "No", "no"),
  binary1 = c(1, "1", "Yes", "yes")
)

Arguments

df

Dataframe.

cols

List of columnn names of binary variables desired to be collapsed.

prefix

String to add to the start of all summary columns names.

suffix

String to add to the end of all summary columns names.

output

List of desired outputs: yesno (any values selected), n (number of values selected) and list (list of column names of all values selected).

remove

Logical value to remove columns supplied to the "cols" parameter

binary0

List of all values corresponding to "0" (No) in the binary variable (default = 0 or no)

binary1

List of all values corresponding to "1" (Yes) in the binary variable (default = 1 or yes).

Value

Dataframe with up to 3 additional columns: yesno (any values selected), n (number of values selected) and list (list of column names of all values selected).


kamclean/collaborator documentation built on Nov. 17, 2023, 3:52 a.m.