[R] Passing in Condtions into Object

Adam Pridgen adam.pridgen at thecoverofnight.com
Fri Sep 9 02:21:45 CEST 2011


Hello,

I am trying to pass a conditional expression into an expression to be
evaluated when ever an R statement is called.  For example:

get_unique_count <- function(df, select, field){
   uniqs <- unique(subset(df, select)[field])
   return (nrow(uniqs))
}


In this case select is a conditional statement year == 1980, and the
function would be called in the following manner:

library(ggplot2)
get_unique_count(mpg, year==1980, 'manufacturer')

Thank for any help in advance,

-- Adam



More information about the R-help mailing list