I want to use something like
library(raster)
library(sp)
## Create raster
r <- raster(ncol=40, nrow=20)
class(r)
## display coordinates
coordinates(r)
## create new coordinates
x <- matrix(rexp(200, rate=.1), ncol=40, nrow=20)
y <- matrix(rexp(200, rate=.1), ncol=40, nrow=20)
## Set new coordinates
coordinates(r)[,1] <- as.vector(x)
coordinates(r)[,2] <- as.vector(y)
but this yields the error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘coordinates<-’ for signature ‘"RasterLayer"’
Is there an easy way to replace the lat longs in a raster?