This function renames variables in a data frame, i.e. it renames the columns of the data frame.
var_rename(x, ...)
x | A data frame. |
---|---|
... | Pairs of named vectors, where the name (lhs) equals the column name that should be renamed, and the value (rhs) is the new column name. |
x
, with new column names for those variables specified in ...
.
# Set variable labels for data frame dummy <- data.frame(a = sample(1:4, 10, replace = TRUE), b = sample(1:4, 10, replace = TRUE), c = sample(1:4, 10, replace = TRUE)) var_rename(dummy, a = "first.col", c = "3rd.col")#> first.col b 3rd.col #> 1 3 4 4 #> 2 4 2 2 #> 3 1 2 4 #> 4 4 2 3 #> 5 1 2 2 #> 6 3 1 3 #> 7 1 1 2 #> 8 2 3 3 #> 9 1 3 3 #> 10 3 4 1