Reputation: 406
I have a data frame, the name of which is wrapped in a variable "my_var". What I am trying to do is to assign a new column names for this data.
What I have tried is:
names(get(my_var)) <- c("Fruits", "Sweets")
assign(names(get(my_var)), c("Fruits", "Sweets"))
within (get(my_var), assign(names(get(my_var)), c("Fruits", "Sweets")))
Neither of this works.
Thanks
Upvotes: 0
Views: 141
Reputation: 532
you can use setnames
from the data.table
package:
setnames(get(my_var), names(get(my_var)), c('a', 'b'))
Upvotes: 1