# A tibble: 18 x 4
sex age time value
<chr> <chr> <chr> <dbl>
1 Female 0-15 2021 13
2 Female 0-15 2022 19
3 Female 0-15 2023 25
4 Female 16-25 2021 22
5 Female 16-25 2022 22
# i 13 more rows
use the pxmake library to convert the dataframe to .rds, .px and .xlsx, like this:
# devtools::install_github('StatisticsGreenland/pxmake')library(pxmake)# from dataframe to rdsrds <-metamake(df)# MATRIX - used also for filename in this examplepx_matrix <-"BEXFIRST"# from dataframe to xlsxmetamake(df, paste0(px_matrix,".xlsx"))# from rds to pxpxmake(rds,paste0(px_matrix,".px"))# view(rds$metadata)# view(rds$data)
The sample dataframe can be edited in Excel or R. Metadata is still too vaguely defined for pxwin to show the file, but pxedit does (of course).
For pxwin to show the px-file, these keywords cannot be blank:
MATRIX, CONTENTS, UNITS, SUBJECT-CODE, SUBJECT-AREA
So update the keywords (can alternatively be edited in Excel):
# add keywordsrds$metadata <- rds$metadata %>%bind_rows(tribble(~keyword, ~language,~variable,~value,"NOTEX","en","age",list("Rough age groups only")))# save metadata changesmetamake(rds, paste0(px_matrix,".xlsx"))# convert to px-filepxmake(input =paste0(px_matrix,".xlsx"), out_path =paste0(px_matrix,".px"))
as can totals. First add metadata, and use the pxmake, add_totals setting
# add metadata for totals rds$metadata <- rds$metadata %>%filter(keyword !="ELIMINATION") %>%bind_rows(tibble(keyword ="ELIMINATION",language ="en",variable =c("age", "sex"),value =list("Total") ))# save metadata changesmetamake(rds, paste0(px_matrix,".xlsx"))# convert to px-file and calculate totalspxmake(input =paste0(px_matrix,".xlsx"), out_path =paste0(px_matrix,".px"),add_totals =c("age","sex"))