Usecase: Pivot

Pivot and change variableorder

library(tidyverse)
library(pxmake)

Check a .px file

Say you have a px-file, where you want to change the default order of variables and also pivot between head and stub.

On the filesystem you have a folder and subfolders, like:

statbank_s_path <- file.path("S:","STATBANK","bank2020","Databases") 

subject_path <- file.path(statbank_s_path,"Greenland","FI") 

Read a px file to px-object

fil <- file.path(subject_path,"FIXUDD.px")

old <- px(fil)

print(px_stub(old))
[1] "type"         "municipality" "education"   
print(px_heading(old))
[1] "time"

Change order/pivot the variables

If multiple variables, define as list

old %>% px_heading(c("municipality","type","education")) %>% 
  px_stub("time") %>% 
  px_save(file.path(subject_path,"FIXUDD_new.px"))

Or do it in Excel

Save px-object to Excel

px_save(old,"FIXUDD_new.xlsx")

Change according to your needs

Save xlsx as px

px_save(px("FIXUDD_new.xlsx"),"FIXUDD_excel_new.px")