Dear R-helpers, I have a number of dataframes that looks something like this:
mydfr <- data.frame(treatment=c(rep("A",3),rep("B",3)), Xmeas=1:6, Ymeas=c(2,4,3,3,5,6)) # except with many more variables, which I plot all the time colored by treatment to quickly check things: with(mydfr, plot(Xmeas, Ymeas, pch=19, col=c("blue","red")[treatment])) # I find it annoying to keep typing in all the bits after Ymeas (yes I use a text editor but that's not the point...) # I tried defining a function like this myplot <- function(...)plot(..., pch=19, col=c("blue","red")[treatment]) # So i can call it like this: with(mydfr, myplot(Xmeas, Ymeas)) # but: Error in plot.xy(xy, type, ...) : object 'treatment' not found I don't understand why the 'with' statement does not allow the 'myplot' function to find the 'treatment' variable (after all, it finds the other variables just fine). Can someone explain why this is, and how to fix this? thanks for your help Remko ------------------------------------------------- Remko Duursma Post-Doctoral Fellow Centre for Plants and the Environment University of Western Sydney Hawkesbury Campus Richmond NSW 2753 Dept of Biological Science Macquarie University North Ryde NSW 2109 Australia Mobile: +61 (0)422 096908 www.remkoduursma.com ______________________________________________ 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.