[Gstat-info] Re: Gstat-info Digest, Vol 40, Issue 6
Greg King
gregspam at kooji.com
Mon Mar 30 22:20:25 CEST 2009
Hi,
This snippet of code probably best summarises the root of my problem;
> class(wind)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
> columns<-names(wind)[2:length(names(wind))]
> class(columns[j])
[1] "character"
> columns[j]
[1] "ugrd_0"
> print(columns[j])
[1] "ugrd_0"
> wind.vgm=variogram(columns[j]~1,sset)
Error: too many spatial dimensions: 162
In addition: Warning messages:
1: In model.matrix.default(Terms, m) :
variable 'columns[j]' converted to a factor
2: NAs introduced by coercion
Your comment is spot on with the variable being of class character (when it
shouldn't be). As you can see from above, I'm getting the name of a
variable form the header column of a data frame. So I suppose the question
is how can I pass this into the variogram as a literal?
Thanks,
Greg
On Mon, Mar 30, 2009 at 7:12 AM, Edzer Pebesma <
edzer.pebesma at uni-muenster.de> wrote:
> Is it possible that variab is of class character, or factor? This should
> not be the case.
>
> What exactly did you mean by "produce the variogram"? After which
> command did you get an error?
> --
> Edzer
>
> Greg King wrote:
> > I'm trying to pass a character vector and data frame into a function
> > that performs ordinary kriging. The function appears to pass the
> > items in correctly, as I can get it to report the class of (or even
> > print) the variables in the function call. However when used to
> > produce the variogram, it fails.
> >
> > Here is the function:
> >
> > gks <- function(inLat,inLon,dframe,variab) {
> > wind.grid <- expand.grid(lat=inLat, lon=inLon)
> > coordinates(wind.grid) <- ~ lat+lon
> > proj4string(wind.grid) <- CRS("+init=epsg:4326")
> > print(class(variab))
> > print(class(dframe))
> > wind.vgm=variogram(variab~1,dframe)
> > wind.fit=fit.variogram(wind.vgm, model=vgm(model="Lin"))
> >
> wind.kriged=krige(variab~1,dframe,wind.grid,model=wind.fit,nmax=9)
> >
> > print(wind.kriged$var1.pred)
> > }
> >
> > Here it the call of the function:
> >
> > gks(1,1,sset,columns[j])
> >
> > Here is the output showing that a character vector and dataframe have
> > been passed in, but then the error that I don't understand...
> >
> > [1] "character"
> > [1] "SpatialPointsDataFrame"
> > attr(,"package")
> > [1] "sp"
> > Error: too many spatial dimensions: 162
> > In addition: Warning messages:
> > 1: In model.matrix.default(Terms, m) :
> > variable 'variab' converted to a factor
> > 2: NAs introduced by coercion
> >
> > Any pointers gratefully received. I'm new to creating functions in R,
> > as you might have guessed.
> >
> > Thanks,
> >
> > Greg
> >
> > Pastebot <http://sf.net/projects/pastebot/> is powered by
> > POE<http://poe.perl.org/>
> > .
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Gstat-info mailing list
> > Gstat-info at geo.uu.nl
> > http://mailman.geo.uu.nl/mailman/listinfo/gstat-info
> >
>
> --
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of Münster
> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
> 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de/
> http://www.springer.com/978-0-387-78170-9 e.pebesma at wwu.de
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.geo.uu.nl/pipermail/gstat-info/attachments/20090330/27299deb/attachment.html
More information about the Gstat-info
mailing list