library(tidyverse)
library(pxmake)
Usecase: Pivot
Pivot and change variableorder
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:
<- file.path("S:","STATBANK","bank2020","Databases")
statbank_s_path
<- file.path(statbank_s_path,"Greenland","FI") subject_path
Read a px file to px-object
<- file.path(subject_path,"FIXUDD.px")
fil
<- px(fil)
old
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
%>% px_heading(c("municipality","type","education")) %>%
old 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")