On Mon, Dec 1, 2008 at 11:06 AM, Vitalie Spinu <[EMAIL PROTECTED]> wrote: > Hello Everyone, > May be a silly question. > > How to pass programmatically variables which are not known in advance and > are quoted? Variables are quoted implicitly in functions like "subset" and > "transform" and explicitly in ggplot and plyr. > > For instance I would like to have something like this: > > myfunc<-functon(mydata,X) subset(mydata,X>4) > myfunc<-function(mydata,X,Y) {ggplot(mydata,aes(x=X,y=Y))+geom_points()}
For subset, just do it by hand: mydata[mydata[[X]] > 4, ] For ggplot, see aes_string: aes_string(x = X, y = Y) which will do what you want For plyr, you can use a character vector: ddply(mtcars, c("cyl"), colwise(mean)) ddply(mtcars, c("cyl ^ 2", "vs - am"), colwise(mean)) In general you need to use substitute or bquote. Hadley -- http://had.co.nz/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.