【发布时间】:2015-06-14 13:31:11
【问题描述】:
类似问题
How to name variables on the fly?
基本上,我想随时随地在 data.frame 中创建一个新列。可能是不好的做法,但对于我正在做的事情来说,这是一个很好的解决方案。
现在我已经试过了:
test <- iris
create.new_var <- function(x) {
assign(paste("test$", x, sep=""), test$Petal.Width)
return(test)
}
test <- create.new.var('cheese')
函数运行时不会中断。但是 data.frame 测试不包含标题为“奶酪”的新列和 iris$Petal.Width 的值,正如人们想象的那样。
【问题讨论】:
标签: r