将字符串变量传递到R函数中

将字符串变量传递到R函数中,r,parameter-passing,user-defined-functions,R,Parameter Passing,User Defined Functions,我想将变量名传递给函数,但似乎无法实现。简单地说 library (reshape) test <- function(x) { cast(data, x ~ ., length) } test(ageg) 我知道这很简单,但我找不到答案。我想让它简单地运行 cast(data, ageg ~ ., length) 试试这个: test <- function (x) cast(data, as.formula(paste0(x , " ~ .")), length) tes

我想将变量名传递给函数,但似乎无法实现。简单地说

library (reshape)
test <- function(x) {
 cast(data, x ~ ., length)
}
test(ageg)
我知道这很简单,但我找不到答案。我想让它简单地运行

cast(data, ageg ~ ., length)
试试这个:

test <- function (x) cast(data, as.formula(paste0(x , " ~ .")), length)

test能否请您在代码开始时输入所用软件包的名称,以使其更易于复制。你不能把一个公式作为参数传递吗?
test <- function (x) cast(data, as.formula(paste0(x , " ~ .")), length)