[R] substitute, eval, quote and functions
David A. van Leeuwen
myfirstname at elseware.nl
Mon Feb 9 00:07:55 CET 2004
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)
}
(which doesn't work, of course---i need a series of `substitute's and
evals---but i can't get it to work---in Perl it would be something along
the lines of $$x, dereferencing $x another time)
so that i can call
scatter.plot(x, one, two)
as a `short' for
plot(x$one, x$two)
In my real application I want to pass the `column selecting' arguments
to `subset', which evan with the code of subset.data.frame I have not
been successful after a whole evening...
Thanks,
--
David A. van Leeuwen < @ElseWare.nl>
Echt stijlvol sterven doe je / bij een ander op de mat
Op de dag dat je bezorgd wordt / door het NRC Handelsblad
---Joop Visser
More information about the R-help
mailing list