【发布时间】:2014-05-16 19:07:33
【问题描述】:
我正在尝试编写一个函数:
myfunc <- function(df, out, ...) { # ... = variables in a dataframe
df <- arrange(df, ...) # plyr function that orders rows
out <- df[!duplicated(df[,c(...)]),] # remove duplicates
}
我不知道如何让 第三行 工作。 "..." 参数只需要转换成字符串向量,这样 !duplicated() 函数就可以工作了。
我知道 deparse(substitute(x)) 适用于 1 个参数:
> foo <- function(x) deparse(substitute(x))
> foo(bar)
[1] "bar"
但它不适用于多个参数。如何更改它以便多个参数起作用?
> foo <- function(...) deparse(substitute(...))
> foo(bar,goo,poo)
[1] "bar" "goo" "poo"
我也欢迎修改原始函数 (myfunc) 的其他解决方案,如果这样做更容易的话。谢谢。
【问题讨论】: