d <-
dplyr::tibble(
q1a = sample(c("y", "n"), size = 200, replace = TRUE),
q1b = sample(c("y", "n", "n", NA), size = 200, replace = TRUE),
q1c = sample(c("y", "y", "n"), size = 200, replace = TRUE),
q1d = sample("n", size = 200, replace = TRUE)
)
d |> combine_answers(q1a:q1d, into = "combined")
d |> combine_answers(q1a:q1d, into = "combined", sep = ", ", value = "y")
d |> combine_answers(q1a:q1d, into = "combined", sep = " | ", value = "n")
# works with survey objects
d |>
srvyr::as_survey() |>
combine_answers(q1a:q1d, into = "combined")
Run the code above in your browser using DataLab