I'm using the 'gstat' package to calculate precipitation values in unknown grids based on known grid values. These grid values pertain to the current location (lon, lat) of a precipitation gauge . The number of rain gauges in northern Canada is limited. To estimate precipitation in unknown grids, I use the following codes. Any grid that is not within 100 kilometres of the precipitation gauge should produce NA, however it does not. Is there anything you could suggest?
x<-Daily_Precip$Lon
y<-Daily_Precip$Lat
z<-Daily_Precip$Precipitation
knowndt=data.frame(x,y,z) #Known Lon, Lat and Location parameter values
coordinates(knowndt)<-~x+y
Daily_grid<-read.csv(file.choose()) # I would like to estimate on the grid lon and lat of this file
x1<-Daily_grid$Lon
y1<-Daily_grid$Lat
unknowndt<-data.frame(x1,y1)
coordinates(unknowndt)<-~x1+y1
idwmodel_Daily_Precip_idp2=idw(z~1, knowndt,unknowndt,nmin =4, nmax=10,maxdist=100,idp=2) # Testing for idp=2
predZ_Daily_Precip_idp2=idwmodel_Daily_Precip_idp2@data$var1.pred
Daily_r1i1p1_idp2<-data.frame(x1,y1,predZ_Daily_Precip_idp2)
write.csv(Daily_Precip_idp2,"Daily_r1i1p1_idp2_Location.csv",row.names=FALSE) # Saving as a csv file