Skip to contents

Several questions in the GBHS can be made into long format data, as they either contain data from multiple choice questions (each answer separated with a ';') or come from a group of questions exploring the same theme with the same response scale. This function collects these questions and responses into dedicated columns where the "key" column in the question asked and responses are stored in "value" ( response category), "continuous" (ordinal scale), and "bin" (binary scale). All other data remain in the data frame, but the number of rows is increased, and the "submission_id" column denotes the individual respondent.

Usage

gbhs_long_q(data, question)

Arguments

data

data.frame to work on. Needs to be a gbhs derivative

question

integer indicating which question to make the data longer from. Values accepted are 1,2,3,4

Value

data frame with long data

Examples

data(gbhs)
gbhs_long_q(gbhs, 2)
#> # A tibble: 302,037 × 100
#>    form_id submis…¹ langu…² langu…³ conse…⁴ age   educa…⁵ gender q01_t…⁶ q03_a…⁷
#>      <dbl>    <dbl> <chr>   <chr>   <chr>   <ord> <fct>   <fct>  <ord>   <ord>  
#>  1  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#>  2  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#>  3  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#>  4  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#>  5  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#>  6  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#>  7  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#>  8  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#>  9  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#> 10  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Very i…
#> # … with 302,027 more rows, 90 more variables: q03_child <ord>,
#> #   q03_middle <ord>, q03_older <ord>, q03_womb <ord>, q03_youngadult <ord>,
#> #   q04_brain_disease <chr>, q05_alcohol_gen <ord>, q05_diet_gen <ord>,
#> #   q05_excercise_gen <ord>, q05_intellect_gen <ord>, q05_protection_gen <ord>,
#> #   q05_relax_gen <ord>, q05_sleep_gen <ord>, q05_smoke_gen <ord>,
#> #   q05_socialise_gen <ord>, q05_supplements_gen <ord>,
#> #   q05_wlbalance_gen <ord>, q06_brainhealth_purp_spec <chr>, …
gbhs_long_q(gbhs, 4)
#> # A tibble: 357,890 × 111
#>    form_id submis…¹ langu…² langu…³ conse…⁴ age   educa…⁵ gender q01_t…⁶ q02_d…⁷
#>      <dbl>    <dbl> <chr>   <chr>   <chr>   <ord> <fct>   <fct>  <ord>   <ord>  
#>  1  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#>  2  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#>  3  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#>  4  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#>  5  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#>  6  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#>  7  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#>  8  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#>  9  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#> 10  114338  4903486 english en      Yes     26-40 "Grad\… Male   Occasi… Modera…
#> # … with 357,880 more rows, 101 more variables: q02_education_infl <ord>,
#> #   q02_genetics_infl <ord>, q02_income_infl <ord>, q02_lifegoals_infl <ord>,
#> #   q02_physenv_infl <ord>, q02_physhealth_infl <ord>,
#> #   q02_profession_infl <ord>, q02_sleep_infl <ord>, q02_socenv_infl <ord>,
#> #   q02_substance_infl <ord>, q03_adolescence <ord>, q03_child <ord>,
#> #   q03_middle <ord>, q03_older <ord>, q03_womb <ord>, q03_youngadult <ord>,
#> #   q05_alcohol_gen <ord>, q05_diet_gen <ord>, q05_excercise_gen <ord>, …