[R] substitute, eval, quote and functions

Douglas Bates bates at stat.wisc.edu
Mon Feb 9 00:19:02 CET 2004


"David A. van Leeuwen" <myfirstname at elseware.nl> writes:

> Hi,
> 
> i am working with large data frames with many dependend variables.  I
> want to write some functions that will allow me to quickly select
> variables from the frame and plot them in various colors depending on
> factor columns, possibly selecting rows according to factor
> conditions. In order to do this in a nice function, i need to
> understand how to work with a column name in the body of a
> function. To simplify my problem, how do i write a function with a
> body like
> 
> 
> scatter.plot <- function (data, x, y) {
>     plot(data$x, data$y)
> }

Use 
   plot(data[[x]], data[[y]])
instead

-- 
Douglas Bates                            bates at stat.wisc.edu
Statistics Department                    608/262-2598
University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/




More information about the R-help mailing list