stacomirtools (version 0.5.3)

chnames: This function replaces the variable names in a data.frame

Description

This function replaces the variable names in a data.frame

Usage

chnames(object, old_variable_name, new_variable_name)

Arguments

object

a data frame

old_variable_name

a character vector with old variables names

new_variable_name

a character vector with new variables names

Value

object

Examples

Run this code
# NOT RUN {
df <- data.frame("var1" = c("blue","red"), "var2" = c("nice","ugly"))
colnames(df) # "var1" "var2"
df <- chnames(object = df, old_variable_name = c("var1","var2"), 
"new_variable_name" = c("color","beauty"))
colnames(df) # "color"  "beauty"
# the following will return an error, as the variable wrong_name is not in variable names
# }
# NOT RUN {
chnames(object = df, old_variable_name = c("wrong_name"), 
"new_variable_name" = c("color")))
# }

Run the code above in your browser using DataLab