I am trying to rename a column using the rename
function but I want to use a variable to assign the column name so I can change the column name programmatically within a for loop.
Here's a pseudo code example of what I am trying to accomplish:
If data
is the format
id, value
1, 300
2, 500
3, 450
....
Then I want to be able to do this
col_name = 'abc_value'
data = data %>%
rename(col_name = value)
So that data is now of the format
id, abc_value
1, 300
2, 500
3, 450
....
But I keep getting data
as :
id,col_name
1, 300
2, 500
3, 450
....
which I don't want.
I have also tried rename(!!sym(col_name) = value
but that just gives me an error. I am not sure how to change the column name using a variable assignment.