我想要一个调用subset
并传递subset
参数的函数:
df <- data.frame(abc=c("A","A","B","B"),value=1:4)
subset(df,abc=="A")
## works of course:
# abc value
#1 A 1
#2 A 2
mysubset <- function(df,ssubset)
subset(df,ssubset)
mysubset(df,abc=="A")
## Throws an error
# Error in eval(expr, envir, enclos) : object 'abc' not found
mysubset2 <- function(df,ssubset)
subset(df,eval(ssubset))
mysubset2(df,expression(abc=="A"))
## Works, but needs expression
我尝试了substitute
,但找不到正确的组合。我怎样才能得到这个工作?