Description Usage Arguments Value Examples
View source: R/change_col_names.R
A data.frame can, by definition, have non unique column names. To change a column name to a new name that is already present in the data.frame might therefore lead to undesiered results. This function handles this problem by dropping the original column cousing the name clash.
1 | change_col_name(x, old_name, new_name, warning = FALSE)
|
x |
data.frame with a column name to change |
old_name |
name (as character string) of column in |
new_name |
new name (as character string) to use instead of |
warning |
should a warning be given if a name clash occours ( |
The same data.frame but with one column named changed. (Note that the output might have one column less if dropped after name clash.)
1 2 3 4 5 6 7 8 9 | ab <- ba <- data.frame(a = letters[1:10], b = 1:10)
# One "traditional" way to change a column name
names(ab)[names(ab) == "a"] <- "b"
names(ab)
ab$b # Returns the first column with name "b"
# Using change_col_names instead:
change_col_name(ba, "a", "b")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.