I have a dataframe with several columns and would like to add a new column and name it according to a previous variable. For example:
df <- data.frame(\"A
In the context of a data.frame name also taken in a variable this might be helpful.
df <- data.frame("A" = c(1, 2, 3, 4), "B" = c("a", "c", "d", "b") ) Variable<-"C" dfname<-"df" df<-within ( assign(dfname , get(dfname) ), assign(Variable, NA ) )