Learn R Programming

umx (version 1.9.1)

umx_rename: umx_rename

Description

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.

Usage

umx_rename(x, replace = NULL, old = NULL, grep = NULL, test = FALSE)

Arguments

x

the dataframe in which to rename variables

replace

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)

old

Optional list of old names that will be found and replaced by the contents of replace. Defaults to NULL

grep

Optional grep string. Matches will be replaced using replace as the replace string. Defaults to NULL

test

whether to report a "dry run" - and not actually change anything (defaults to false)

Value

- dataframe with columns renamed.

Details

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")

See Also

Other Utility Functions: qm, umx_find_object, umx_msg, umx_names, umx_paste_names, umx_pb_note, umx_print, umx

Examples

Run this code
# 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" does not 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