Skip to contents

This function processes checkbox matrix variables in a dataset, transforming their representations into one of the specified formats.

Usage

ns_alter_checkbox(data, to = c("character", "list"), sep = ",", cb = NULL)

Arguments

data

A `data.frame` containing the dataset to modify.

to

A character string specifying the output format for checkbox matrix variables. Must be one of "character" or "list".

sep

A character string used as a separator when `to = "character"`. Defaults to `","`.

cb

An optional codebook (`data.frame`) to identify checkbox matrix variables. If `NULL`, the codebook is generated using `ns_get_codebook()`.

Value

A modified `data.frame` with processed checkbox matrix variables.

Examples

dt <- ns_get_data(123823)
cb <- ns_get_codebook(123823)
ns_alter_checkbox(dt, to = "list", cb = cb)
#>   $submission_id formid                  $created       freetext radio
#> 1       27685292 123823 2023-06-01T20:57:15+02:00      some text     1
#> 2       27685302 123823 2023-06-01T20:58:33+02:00 another answer    -1
#> 3       27685319 123823 2023-06-01T20:59:50+02:00                   -1
#>   checkbox.questionnaires checkbox.events checkbox.logs dropdown
#> 1                       1               1             0        4
#> 2                       0               0             1        9
#> 3                       1               1             1        4
#>   radio_matrix.grants radio_matrix.lecture radio_matrix.email       date  time
#> 1                   1                    2                  2 2023-06-01 12:00
#> 2                   3                    3                  1 2023-02-07 14:45
#> 3                   1                    1                  1 2022-09-28 05:11
#>           datetime number_decimal number_integer slider attachment_1
#> 1 2023-06-12T13:33            4.5           77.0      3    sølvi.png
#> 2 2024-02-15T08:55            2.2           45.0      1             
#> 3 2022-03-03T07:29           10.0           98.0      9             
#>   attachment_2 $answer_time_ms   checkbox_matrix.1           checkbox_matrix.2
#> 1                        74630       IT, colleague                       admin
#> 2  marius.jpeg           71313            internet                admin, union
#> 3                        70230 colleague, internet IT, admin, colleague, union
ns_alter_checkbox(dt, to = "character", sep = ";", cb = cb)
#>   $submission_id formid                  $created       freetext radio
#> 1       27685292 123823 2023-06-01T20:57:15+02:00      some text     1
#> 2       27685302 123823 2023-06-01T20:58:33+02:00 another answer    -1
#> 3       27685319 123823 2023-06-01T20:59:50+02:00                   -1
#>   checkbox.questionnaires checkbox.events checkbox.logs dropdown
#> 1                       1               1             0        4
#> 2                       0               0             1        9
#> 3                       1               1             1        4
#>   radio_matrix.grants radio_matrix.lecture radio_matrix.email       date  time
#> 1                   1                    2                  2 2023-06-01 12:00
#> 2                   3                    3                  1 2023-02-07 14:45
#> 3                   1                    1                  1 2022-09-28 05:11
#>           datetime number_decimal number_integer slider attachment_1
#> 1 2023-06-12T13:33            4.5           77.0      3    sølvi.png
#> 2 2024-02-15T08:55            2.2           45.0      1             
#> 3 2022-03-03T07:29           10.0           98.0      9             
#>   attachment_2 $answer_time_ms  checkbox_matrix.1        checkbox_matrix.2
#> 1                        74630       IT;colleague                    admin
#> 2  marius.jpeg           71313           internet              admin;union
#> 3                        70230 colleague;internet IT;admin;colleague;union