separate_multiple_choice: separate multiple choice

View source: R/separate_multiple_choice.R

separate_multiple_choiceR Documentation

separate multiple choice

Description

Aufdroeseln von Mehrfachantworten

Usage

separate_multiple_choice(
  x,
  sep = ", ",
  id = 1:length(x),
  out_levels = 1:0,
  out_labels = NULL,
  as_logical = is.null(out_labels),
  prafix = NULL,
  into = NULL,
  label = NULL,
  na.strings = NULL
)

Arguments

x

Vektor ist entweder ein Character oder eine zahl Bei Zahlen gehen nur 1 bis 11

sep

wichtig ist das trennzeichen

id

unique id

out_labels, out_levels

Outut nimmeric oder factor

as_logical

ausgabe logical

prafix

neue Variablen Name fuer die ausgabe default ist der Name vom Input

into

brauch nicht gesetzt werden entspricht der Anzahl an levels

label

Labels

na.strings

missing

Details

separate_multiple_choice() Aufdröseln vom Mehrfachantworten, die Funktion transformiert einen String mit Trennzeichen zu einem Multi-Set mit 0 und 1. (Separate multiple choice)

Value

data.frame mit 0 1 Kodierung und den Fragen als Labels

Examples

#' #require(stp25tools)
lbl <- c (
  '1 Heart Failure' = 1,
  '2 Rhythm Abnormality' = 2,
  '3 Valve Dysfunction' = 3,
  '4 Bleeding with OAC' = 4,
  '5 ACS' = 5,
  '6 Neurological Event' = 6,
  '7 Neoplastic Disease' = 7,
  '8 Others' = 8,
  '0 No Complications' = 0
)

x <- c(0,
       "1,3,6,8,4",
       2,
       "",
       "8,4",
       "4,6,8,3",
       "2,3,4,5")

rslt <-
  separate_multiple_choice(x ,
                           sep = ",",
                           as_logical = TRUE,
                           label = lbl)
# stp25stat2::Tbll_desc(rslt)


dat <-  data.frame(
  Q1 = c(134, NA, 35, 134, 5, 24),
  Q2 = c(
    "Alm Dudler, Essig, Cola",
    NA,
    "Cola, Holer",
    "Alm Dudler, Cola, Essig",
    "Holer",
    "Bier, Essig"
  )
)


dat2 <- cbind(dat[2],
              separate_multiple_choice(dat$Q2))
names(dat2) <- get_label(dat2)
dat2


dat1 <- cbind(dat[1],
              separate_multiple_choice(dat$Q1,
                                       label =
                                         c(
                                           "Alm Dudler",
                                           "Bier",
                                           "Cola",
                                           "Essig",
                                           "Holer"
                                         )))
names(dat1) <- get_label(dat1)
dat1


x <- data.frame(A = c(15911, 261011, 3711, 48111))
separate_multiple_choice(x$A)



stp4/stp25tools documentation built on Feb. 27, 2025, 11:14 p.m.