The short()
can be useful for validation, if you need to transform the dataset and create one column for a variable with different events. You also need to create the excel document, where the name and number of columns can be any. If you have common columns, pass them to a parameter common_cols
of short()
. Notice, don’t write common columns in the excel document. If you have the extra information e.g. the understandable name of an analysis, pass it to a parameter extra
.
Some examples, where you can use short()
.
yn | res |
---|---|
preg_yn | preg_res |
id | site | sex | preg_yn_e2 | preg_res_e2 | preg_yn_e3 | preg_res_e3 |
---|---|---|---|---|---|---|
01 | site 01 | f | y | neg | y | neg |
02 | site 02 | m | y | neg | y | pos |
03 | site 03 | f | y | neg | n | unnes |
preg <- system.file("preg.xlsx", package = "dmtools")
obj_short <- short(preg, id, "res", c("site", "sex"))
obj_short <- obj_short %>% check(df)
obj_short %>% get_result()
#> id site sex yn res name_to_find
#> 1 01 site 01 f y neg preg_res_e2
#> 2 01 site 01 f y neg preg_res_e3
#> 3 02 site 02 m y neg preg_res_e2
#> 4 02 site 02 m y pos preg_res_e3
#> 5 03 site 03 f y neg preg_res_e2
#> 6 03 site 03 f n unnes preg_res_e3
type | amount |
---|---|
drug_type | drug_amount |
id | drug_type_e2 | drug_amount_e2 | drug_type_e3 | drug_amount_e3 |
---|---|---|---|---|
01 | type_one | 2 | type_one | 2 |
02 | type_two | 1 | type_two | 1 |
03 | type_one | 2 | type_one | 1 |
drug <- system.file("drug.xlsx", package = "dmtools")
obj_short <- short(drug, id, "type")
obj_short <- obj_short %>% check(df)
obj_short %>% get_result()
#> id type amount name_to_find
#> 1 01 type_one 2 drug_type_e2
#> 2 01 type_one 2 drug_type_e3
#> 3 02 type_two 1 drug_type_e2
#> 4 02 type_two 1 drug_type_e3
#> 5 03 type_one 2 drug_type_e2
#> 6 03 type_one 1 drug_type_e3
heart | resp |
---|---|
hr | respr |
id | hr_e2 | respr_e2 | hr_e3 | respr_e3 |
---|---|---|---|---|
01 | 60 | 12 | 65 | 13 |
02 | 70 | 15 | 71 | 14 |
03 | 76 | 16 | 86 | 18 |
lab | is_norm | cl | human_name |
---|---|---|---|
ast | ast_norm | ast_cl | enzyme_ast |
id | ast_e2 | ast_norm_e2 | ast_cl_e2 | ast_e3 | ast_norm_e3 | ast_cl_e3 | ae_yn_e5 | ae_desc_e5 |
---|---|---|---|---|---|---|---|---|
01 | 32 | norm | NA | 36 | norm | NA | no | NA |
02 | 56 | no | no | 80 | no | yes | yes | abnormal ast |
03 | 60 | no | yes | 32 | norm | NA | no | NA |
ae <- system.file("ae.xlsx", package = "dmtools")
obj_short <- short(ae, id, "is_norm", common_cols = c("ae_yn_e5", "ae_desc_e5"), extra = "human_name")
obj_short <- obj_short %>% check(df)
obj_short %>% get_result()
#> id ae_yn_e5 ae_desc_e5 lab is_norm cl name_to_find human_name
#> 1 01 no <NA> 32 norm <NA> ast_norm_e2 enzyme_ast
#> 2 01 no <NA> 36 norm <NA> ast_norm_e3 enzyme_ast
#> 3 02 yes abnormal ast 56 no no ast_norm_e2 enzyme_ast
#> 4 02 yes abnormal ast 80 no yes ast_norm_e3 enzyme_ast
#> 5 03 no <NA> 60 no yes ast_norm_e2 enzyme_ast
#> 6 03 no <NA> 32 norm <NA> ast_norm_e3 enzyme_ast