Skip to contents

This function recreates the columns for select multiple questions

Usage

recreate_parent_column(
  dataset,
  uuid_column = "uuid",
  kobo_survey = NULL,
  kobo_choices = NULL,
  sm_separator = ".",
  cleaning_log_to_append = NULL
)

Arguments

dataset

data frame

uuid_column

uuid column in the dataset. Default is "uuid".

kobo_survey

Kobo survey sheet.

kobo_choices

Kobo choices sheet.

sm_separator

Separator for choice multiple questions. The default is "."

cleaning_log_to_append

A cleaning log where to add the changes from this functions. Names of the log from this function are "uuid", "question", "change_type", "new_value", "old_value", "comment". If the cleaning_log_to_append names are not matching, the only way is to create without a cleaning_log_to_append, and rename the columns and then bind.

Examples

test_data <- dplyr::tibble(
  uuid = paste0("uuid_", 1:6),
  gender = rep(c("male", "female"), 3),
  reason = c(
    "xx,yy", "xx,zy",
    "zy", "xx,xz,zy",
    NA_character_, "xz"
  ),
  reason.xx = c(0, 1, 0, 1, 0, 0),
  reason.yy = c(1, 0, 0, 0, 1, 0),
  reason.xz = c(0, 0, 0, 1, 0, 1),
  reason.zy = c(0, 1, 1, 1, 0, 0),
  reason_zy = c(NA_character_, "A", "B", "C", NA_character_, NA_character_)
)
recreate_parent_column(dataset = test_data, uuid_column = "uuid", sm_separator = ".")
#> gender
#> reason.xx
#> reason.yy
#> reason.xz
#> reason.zy
#> reason_zy
#> gender
#> reason.xx
#> reason.yy
#> reason.xz
#> reason.zy
#> reason_zy
#> gender
#> reason
#> reason.xx
#> reason.yy
#> reason.xz
#> reason.zy
#> reason_zy
#> $data_with_fix_concat
#> # A tibble: 6 × 8
#>   uuid   gender reason   reason.xx reason.yy reason.xz reason.zy reason_zy
#>   <chr>  <chr>  <chr>        <dbl>     <dbl>     <dbl>     <dbl> <chr>    
#> 1 uuid_1 male   yy               0         1         0         0 NA       
#> 2 uuid_2 female xx zy            1         0         0         1 A        
#> 3 uuid_3 male   zy               0         0         0         1 B        
#> 4 uuid_4 female xx xz zy         1         0         1         1 C        
#> 5 uuid_5 male   yy               0         1         0         0 NA       
#> 6 uuid_6 female xz               0         0         1         0 NA       
#> 
#> $correction_parent_sm_log
#>     uuid question     change_type new_value old_value
#> 1 uuid_1   reason change_response        yy     xx,yy
#> 2 uuid_2   reason change_response     xx zy     xx,zy
#> 3 uuid_4   reason change_response  xx xz zy  xx,xz,zy
#> 4 uuid_5   reason change_response        yy      <NA>
#>                                           comment
#> 1 Parent column changed to match children columns
#> 2 Parent column changed to match children columns
#> 3 Parent column changed to match children columns
#> 4                             NA changed to value
#>