Last chance! 50% off unlimited learning
Sale ends in
Returns a dataframe with variables renamed as desired. Unlike some functions, it checks that the variables exist, and that the new names are not already used.
umx_rename(x, replace = NULL, old = NULL, grep = NULL, test = FALSE)
the dataframe in which to rename variables
If used alone, a named collection of c(oldName = "newName") pairs OR, if "old" is a list of existing names, the list of new names) OR, if "grep" is a regular expression, the replace string)
Optional list of old names that will be found and replaced by the contents of replace. Defaults to NULL
Optional grep string. Matches will be replaced using replace as the replace string. Defaults to NULL
whether to report a "dry run" - and not actually change anything (defaults to false)
- dataframe with columns renamed.
As a courtesy function, it handles grep replace in strings of characters.
note: to use replace list, you must say c(old = "new"), not c(old -> "new")
Other Utility Functions: qm
,
umx_find_object
, umx_grep
,
umx_msg
, umx_names
,
umx_paste_names
, umx_pb_note
,
umx_print
, umx
# NOT RUN {
# Re-name "cyl" to "cylinder"
x = mtcars
x = umx_rename(x, replace = c(cyl = "cylinder"))
# alternate style
x = umx_rename(x, old = c("disp"), replace = c("displacement"))
umx_check_names("displacement", data = x, die = TRUE)
# This will warn that "disp" doesn't exist (anymore)
x = umx_rename(x, old = c("disp"), replace = c("displacement"))
x = umx_rename(x, grep = "lacement", replace = "") # using grep to revert to disp
umx_names(x, "^d") # all names begining with a d
# }
Run the code above in your browser using DataLab