I have a data frame which contains point daily precipitation for 4 station for 2 years. I want to interpolate to 50m resoulution and write them in to 2 raster images. I used following code to achieve this...
library(ggplot2)
library(gstat)
library(maptools)
library(raster)
library(rgdal)
xcord<-c(100,200,300,400)
ycord<-c(100,200,300,400)
value1<-c(1,2,3,1)
value2<-c(2,5,7,3)
datas<-data.frame(xcord,ycord,value1,value2)
coordinates(datas) = ~xcord+ycord
mesh <- expand.grid(x=seq(0,500,50),y=seq(0,500,50))
coordinates(mesh)=~x+y
gridded(mesh) <- TRUE
oneidw = idw(value1~1,datas,mesh)
spplot(oneidw["var1.pred"], main = " inverse distance weighted interpolations")
It worked. but i want to apply a loop to do it for another variable value2 (and so on...) without doing it manually. and i used this
sym<-paste("value", 1:2,sep="")
variable=as.vector(print(sym,quote=FALSE))
for (i in 3:ncol(datas)){
one<-idw((print(variable[i],quote=FALSE))~1,datas,mesh)
}
but i got error too many spatial dimensions........ can anybody help me with this....