Renames any columns of a data.frame (from 1 to as much columns as you want).

rename_col(df, old.col.names, new.col.names)

Arguments

df

a data.frame

old.col.names

a character vector of column names to rename

new.col.names

a character vector of column new names

Value

The same data.frame as df.

Examples

df <- cbind.data.frame(a = 1:10, b = 1:10, c = 1:10, d = 1:10)
df
#>     a  b  c  d
#> 1   1  1  1  1
#> 2   2  2  2  2
#> 3   3  3  3  3
#> 4   4  4  4  4
#> 5   5  5  5  5
#> 6   6  6  6  6
#> 7   7  7  7  7
#> 8   8  8  8  8
#> 9   9  9  9  9
#> 10 10 10 10 10

rename_col(df, 
           old.col.names = c("a", "d"), 
           new.col.names = c("aa", "dd"))
#>    aa  b  c dd
#> 1   1  1  1  1
#> 2   2  2  2  2
#> 3   3  3  3  3
#> 4   4  4  4  4
#> 5   5  5  5  5
#> 6   6  6  6  6
#> 7   7  7  7  7
#> 8   8  8  8  8
#> 9   9  9  9  9
#> 10 10 10 10 10