I had the same issue and this piece of code worked out for me.
names(data)[names(data) == "oldVariableName"] <- "newVariableName"
In short, this code does the following:
names(data)
looks into all the names in the dataframe (data
)
[names(data) == oldVariableName]
extracts the variable name (oldVariableName
) you want to get renamed and <- "newVariableName"
assigns the new variable name.