Im have a data set with many variables (50 variables). Im put a short example.
Im try to find a way to create a news variables depend some other, but not all variables and add the prefix NEW_ Because is a process for clean up and update data.
When the new variable appear next to the original variable:
PAIS_ORIGEN ... NEW_PAIS_ORIGEN ... DEPARTAMENTO ... NEW_DEPARTAMENTO
Im run the code but the new variables appear with data, the idea is create a new variables in white spaces for make the fixes in this space.
ACCESION ESTADO PAIS_ORIGEN LATITUD ALTITUD NEW_PAIS_ORIGEN NEW_LATITUD NEW_ALTITUD
1 G123 AV USA 42.02 20.34 USA 42.02 20.34
2 G345 NAV COL 40.02 21.64 COL 40.02 21.64
3 G567 AV BRA 41.05 40.84 BRA 41.05 40.84
4 G342 NAV PRU 39.45 50.34 PRU 39.45 50.34
So you are not trying to make calculations programmatically but to put together a printable table that you can manually fill? If that is the case I don't see a pattern that could allow to specify the column order more efficiently, I think you are going to need to manually specify your desired order or maybe use the word "new" as a sufixe instead of a prefixe, then if you reorder alphabetically the columns will remain together.
The idea is to be able to build the new variables blank and next to the original to facilitate corrections. It would be just a virtual format to enter the data.
To avoid doing that order of columns manually when there are many.
On the other hand, using your code the new columns do appear, but they keep the data, the idea is that these new columns are blank.
I am trying to make a general process to apply it on different databases.