Hi everyone,
I'm trying to create a variogram using packages gstat and sp.
the script goes as follow :
reszn <- read_excel("C:/....../residuszn.xlsx")
head(reszn)
coordinates(reszn)=~x+y
class(reszn)
vario_reszn<-variogram(reszn~1, data=reszn)
plot(vario_reszn)
the class(reszn) gives me this output :
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
so it does not seem to have any issue at this point
but when it comes to
vario_reszn<-variogram(reszn~1, data=reszn)
I have this error popping out
Error in model.frame.default(terms(formula), as(data, "data.frame"), na.action = na.fail) :
the object isn't a matrix
I tried to convert my spatialized dataframe as a matrix using
mreszn<-data.matrix(reszn,rownames.force = FALSE)
and I have this error :
Error in as.vector(data) :
No method to automaticaly convert this S4 class into vector.
So I don't know what to do anymore... Any help would be very welcome
thanks
PS : error messages have been translated from french
PPS: I don't have any NA in my data frame.
Could you try and create a reprex of this issue so we can better understand and debug it? A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:
here it is
df<-data.frame(
x = c(142440.41,142961.81,143267.33,
143236,143665.82,142813.32),
y = c(167843.83,168237.34,168085.43,
168213.28,169220.81,169094.54),
residualZn = c(0.488249621071484,
-0.172036591379516,0.117844597600621,
0.617521750723651,-0.286365623586011,
-0.0886741489196016)
)