On 6/15/07, hadley wickham <[EMAIL PROTECTED]> wrote:
> On 6/15/07, Deepayan Sarkar <[EMAIL PROTECTED]> wrote:
[...]
> > By 'name', I mean a symbol, such as 'Age' or 'myweight'. So
> > basically, everything is as you would expect if the name is visible in
> > data, but if not, the search starts in the environment of the formula,
> > not the environment where the function call is being made (which is
> > the standard evaulation behaviour). This is a feature, not a bug
> > (things would be a lot more confusing if it were the other way round).
>
> Could you give an example? It's always seemed confusing to me and I
> don't see why looking in the environment of the formula helps.
Good question. I remember being convinced that it was a good idea, but
no longer remember why. This is the best I can come up with right now:
## stupid function that fits a model on a random subsample
lmsub <- function(formula, data, p = 0.7)
{
n <- nrow(data)
newdata <- data[sample(round(n * p)), ]
lm(formula, newdata)
}
mydata <- data.frame(x = 1:100, y = rnorm(100))
n <- 2
lmsub(y ~ poly(x, n), data = mydata)
I don't think the use of the name 'n' is unusual in either case, and
we definitely wouldn't want the one inside 'lmsub' to be used for the
formula.
-Deepayan
______________________________________________
[email protected] 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.