将data.framework列名传递给函数
x
column
fun1
fun2
x$column
max()
substitute()
eval()
fun1 <- function(x, column){ do.call("max", list(substitute(x[a], list(a = column))))}fun2 <- function(x, column){ max(eval((substitute(x[a], list(a = column)))))}df <- data.frame(B = rnorm(10))fun1(df, "B")fun2(df, "B")
fun(df, B)
column
substitute()
with(x, get(column))
substitute
formula()
match.call()
子问题do.call()
eval()
?
摇曳的蔷薇
慕尼黑8549860