我想有它調用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
嘗試過,但沒能找到合適的組合。我怎樣才能得到這個工作?
看一看這樣的:https://github.com/hadley/ devtools/wiki /評價 – James 2012-08-09 10:05:49
詹姆斯,感謝您的鏈接,它*非常*富有洞察力! – 2012-08-09 11:27:29
相關問題:http://stackoverflow.com/questions/9860090/in-r-why-is-better-than-subset – flodel 2012-08-09 11:33:42