Click here to Skip to main content
15,883,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to create a semivariogram, but my code no use.
command window shows me:

Error in validObject(.Object) :
invalid class “SpatialPointsDataFrame” object: invalid object for slot "data" in class "SpatialPointsDataFrame": got class "SpatialPointsDataFrame", should be or extend class "data.frame"


could you please help me?

What I have tried:

install.packages("gstat")

library(gstat)

install.packages("sf")

library(sf)

install.packages("sp")

library(sp)

install.packages("geoR")

library(geoR)

install.packages("devtools")

library(devtools)

#library('mapping')

TheData=read.csv("C:/Users/hp/Desktop/myfile.csv")

plot(TheData$Var5,TheData$Var4)

#load the sp library
library(sp)

#remove any null data rows
TheData=na.omit(TheData)

#convert simple data frame into a spatial data frame object
coordinates(TheData)= ~ Var4+Var5

#create a bubble plot with the random values
##bubble(TheData, zcol='m_rand', fill=TRUE, do.sqrt=FALSE, maxsize=3)

#TheVariogram=variogram(m_rand~1, data=TheData)
#plot(TheVariogram)

###fit_var = gstat::fit.variogram(object = , model = )
###TheVariogramModel <- vgm(psill=0.15, model="Gau", nugget=0.0001, range=5)

f_spdf= sp::SpatialPointsDataFrame(coords = cbind(TheData$Var5,TheData$Var4), data=TheData, proj4string = sp::CRS(projargs = "+ init=epsg:32631"))

vario = gstat::variogram(object = TheData ~ 1, locations = f_spdf)
Posted
Updated 22-Oct-22 0:14am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900