# NOT RUN {
r <- raster(nrow=5, ncol=5, xmn=0, xmx=10, ymn=0, ymx=10, crs=NA)
set.seed(1)
values(r) <- sample(1:25)
r[r < 15] <- NA
xyz <- rasterToPoints(r)
rst <- rasterFromXYZ(xyz)
# equivalent to:
rr <- raster(nrow=5, ncol=5, xmn=0, xmx=10, ymn=0, ymx=10)
cells <- cellFromXY(rr, xyz[,1:2])
rr[cells] <- xyz[,3]
# multiple layers
xyzz <- cbind(xyz, a=1:nrow(xyz), b=nrow(xyz):1)
b <- rasterFromXYZ(xyzz)
# }
Run the code above in your browser using DataLab