Similar to question
How to name variables on the fly?
Basically I want to create a new column in a data.frame on the go. Might be bad practice, but for what i'm doing its a good solution.
Right now I've tried :
test <- iris
create.new_var <- function(x) {
assign(paste("test$", x, sep=""), test$Petal.Width)
return(test)
}
test <- create.new.var('cheese')
the function runs without breaking. But the data.frame test does not contain a new column with a heading 'cheese' and the values of iris$Petal.Width as one would imagine it should.