Skip to content
Prev 165034 / 398506 Next

passing arguments to subset from a function

On Wed, 17 Dec 2008 20:07:08 +0100, GOUACHE David <D.GOUACHE at arvalisinstitutduvegetal.fr> wrote:
I would use the example of .() function from plyr package in this case:

.<-function (...){
     structure(as.list(match.call()[-1]), class = "quoted")
}

myfunction<-function(table, extraction)  {
     table2<-subset(table, eval(extraction[[1]]))
     return(table2)
 }
myfunction(iris, extraction = .(Species=="setosa"))

You can pass as many arguments in .() as you wish and index correspondingly in myfunction afterwards.

HTH.