Data Science Desktop Survival Guide
by Graham Williams |
|||||
Normalise Variable Names |
Variable names are normalised so as to have some certainty in interacting with the data. The convenience function rattle::normVarNames() can do this.
# Review the variables before normalising their names.
names(ds)
# Capture the original variable names for use in plots.
vnames <- names(ds) # Normalise the variable names. ds %<>% rename_all(normVarNames) # Confirm the results are as expected. names(ds)
# Index the original variable names by the new names.
names(vnames) <- names(ds) vnames
Notice that we capture the original variable names in the variable []vnames for reference, and particularly when generating plots and wanting to use the original names. The variable names now conform to our expectations of them and in accordance to our chosen style as documented in Chapter 23.
|