【发布时间】:2012-08-14 11:22:41
【问题描述】:
使用变量名分配给数据框列。
getModified <- function(dframe, destination_string, foo, bar) {
# complex calculations on foo and bar getting mynewcol here
# ...
# I want to add mynewcolumn with name in destination_string
# if "blah" was the destination_string, the result would be as:
#dframe$blah <- mynewcol
#return(dframe)
# what is the syntax for using the variable?
# no luck here:
dframe[, destination_string] <- mynewcolumn
return(dframe)
}
这样我就可以打电话了
dframe <- getModified(dframe, "nameofmynewcolum", foo, bar)
dframe$nameofmynewcolumn
【问题讨论】:
-
到底是什么问题?这似乎对我有用。
-
好吧,你看一下...他们都工作...我想知道发生了什么。