[R] using names() as a variable in a formula
Duncan Murdoch
dmurdoch at pair.com
Wed Feb 18 22:14:13 CET 2004
On Wed, 18 Feb 2004 15:44:59 -0500, "femke" <femke at geog.umd.edu> wrote
>> v<-variogram(A1~1,loc=~x+y, dataC)
What package is variogram in? The one in spatial takes different
args.
>> v<-variogram(names(dataC[3])~1,loc=~x+y, dataC)
Doing this sort of thing is tricky. Your names(dataC[3]) is a
character string; you want something there that would be interpreted
as a name instead. However, as.name(names(dataC[3])) isn't enough.
I think you need to build up the formula using fairly low level stuff,
something like this:
formula <- as.call(list(as.name('~'), as.name(names(dataC[3])),
quote(1)))
and then do
variogram(formula, ....)
but a formula constructed this way doesn't work in lm(), so it may not
work in variogram either.
Duncan Murdoch
More information about the R-help
mailing list