Skip to contents

This utility function reorders the data set to match the data dictionary.

Usage

reorder_data(DD.dict, DS.data)

Arguments

DD.dict

Data dictionary.

DS.data

Data set.

Value

Updated data set with variables reordered to match the data dictionary.

Examples

data(ExampleN)
name_check(DD.dict.N, DS.data.N)
#> $Message
#> [1] "ERROR: the variable names match between the data dictionary and the data, but they are in the wrong order. Consider using reorder_dictionary function to automatically reorder the dictionary so that you can continue working through the checks."
#> 
#> $Information
#> # A tibble: 10 × 2
#>    Data                       Dict                      
#>    <chr>                      <chr>                     
#>  1 Data: ABD_CIRC             Dict: HIP_CIRC            
#>  2 Data: HIP_CIRC             Dict: ABD_SKF             
#>  3 Data: ABD_SKF              Dict: SUP_SKF             
#>  4 Data: SUP_SKF              Dict: ABD_CIRC            
#>  5 Data: BP_DIASTOLIC         Dict: HTN                 
#>  6 Data: HTN                  Dict: SMOKING_HX          
#>  7 Data: SMOKING_HX           Dict: LENGTH_SMOKING_YEARS
#>  8 Data: LENGTH_SMOKING_YEARS Dict: HEART_RATE          
#>  9 Data: HEART_RATE           Dict: PHYSICAL_ACTIVITY   
#> 10 Data: PHYSICAL_ACTIVITY    Dict: BP_DIASTOLIC        
#> 
DS.data_updated <- reorder_data(DD.dict.N, DS.data.N)
#> $Message
#> [1] "CORRECTED ERROR: the variable names match between the data dictionary and the data, but they were in the wrong order. ***ALERT**** this function has temporarily reordered the dictionary to match the data so that you can continue working through the checks."
#> 
#> $Information
#> # A tibble: 10 × 3
#>    Data                       Dict                       New.Data               
#>    <chr>                      <chr>                      <chr>                  
#>  1 Data: ABD_CIRC             Dict: HIP_CIRC             Dict: HIP_CIRC         
#>  2 Data: HIP_CIRC             Dict: ABD_SKF              Dict: ABD_SKF          
#>  3 Data: ABD_SKF              Dict: SUP_SKF              Dict: SUP_SKF          
#>  4 Data: SUP_SKF              Dict: ABD_CIRC             Dict: ABD_CIRC         
#>  5 Data: BP_DIASTOLIC         Dict: HTN                  Dict: HTN              
#>  6 Data: HTN                  Dict: SMOKING_HX           Dict: SMOKING_HX       
#>  7 Data: SMOKING_HX           Dict: LENGTH_SMOKING_YEARS Dict: LENGTH_SMOKING_Y…
#>  8 Data: LENGTH_SMOKING_YEARS Dict: HEART_RATE           Dict: HEART_RATE       
#>  9 Data: HEART_RATE           Dict: PHYSICAL_ACTIVITY    Dict: PHYSICAL_ACTIVITY
#> 10 Data: PHYSICAL_ACTIVITY    Dict: BP_DIASTOLIC         Dict: BP_DIASTOLIC     
#> 
name_check(DD.dict.N, DS.data_updated)
#> $Message
#> [1] "Passed: the variable names match between the data dictionary and the data."
#> 
#> $Information
#> [1] "Variable names matched"
#>