I want to perform IDW interpolation using R using the idw command from the gstat package. I have this data:
A tibble: 40 × 7
Fecha Dispositivo Id x y Altura Tmin
1 2024-05-15 J72893 72893 246734 6223612 282 0.23
2 2024-05-15 J72506 72506 247291 6226657 247 -3.52
3 2024-05-15 J71625 71625 245754 6226497 288 1.7
the code is:
your text
library(pacman)
your text
p_load(sf,raster, rgeos, wesanderson, sp, mapview, gsstat, tidyverse, readx1)
your text
mapview()
your text
fnc <- shapefile(‘C:UsersponceOneDriveEscritorioSan+VicenteSan Vicente.shx’) `#is the area of interest
your text
ext <- extent(fnc)
your text
grd <- expand.grid(x <- seq(from = ext[1], to =ext[2], by = 10),
y <- seq(from = ext[3], to =ext[4], by = 10))
your text
names(grd) <- c(“x”, “y”)
your text
coordinates(grd) <- c(“x”, “y”)
your text
gridded(grd) <- TRUE
your text
crs(grd) <- crs(fnc)
your text
info <- read_excel(“C:/Users/ponce/OneDrive/Escritorio/info.xlsx”)
your text
pts <- info
your text
coordinates(pts) <- ~ x + y
your text
crs(pts) <- crs(fnc)
your text
idw.p <- gstat::idw(Tmin ~ 1, pts, newdata = intento, idp=2)
but give me:
Data summary:
var1.pred var1.var
Min. :-2.068 Min. : NA
1st Qu.:-2.068 1st Qu.: NA
Median :-2.068 Median : NA
Mean :-2.068 Mean :NaN
3rd Qu.:-2.068 3rd Qu.: NA
Max. :-2.068 Max. : NA
NA’s :49952
If I made the grill in another way. The error remains, as I put below:
your text
Grid <- as.data.frame(spsample(pts, “regular”, n =50000))
your text
names(Grid) <- c(“x”,”y”)
your text
coordinates(Grid) <- c(“x”,”y”)
your text
gridded(Grid) <- TRUE
your text
fullgrid(Grid) <- TRUE
your text
proj4string(pts) <- proj4string(pts)
your text
proj4string(Grid) <- proj4string(pts)
Zerbak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.