Reputation: 1
I'm trying to create a semivariogram in R, giving it data from a raster coming from a GeoTif file. The version of Rstudio I'm running is the "Elsbeth Geranium" Release (7d165dcf, 2022-12-03) for Windows and my OS is windows 10 home.
The variogram function from the gstat
package is giving me this error:
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘gridded’ for signature ‘"data.frame"’
My lines of code were:
library(sp)
library(raster)
library(gstat)
A <- raster("C:/Users/Mark/EX.tif",5) #to create a raster from the fith layer of EX.tif
ptA <- rasterToPoints(A) #to extract the coordinates
dfA <- as.data.frame(A) #to convert the raster A as a dataframe
v <- gstat::variogram(object = EX_1~1, locations = ptA, data = dfA)
I expected to create a variogram object, obtained that error message.
I hope to finally understand the variogram function, what kind of data it needs as input and how to give this input obtaining it from a GeoTif file.
Upvotes: 0
Views: 142
Reputation: 1
the error means that the input class is not correct. you should include a gstat object as input, not a dataframe. Try to transform your dataframe to a spatial object, then calculate the semivariogram:
coordinates(dfA)= ~ x + y
v <- gstat::variogram(object = EX_1 ~1, data = dfA)
Upvotes: 0