Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm using the function rasterToPoints() from the package raster . By default, this function omits the NA values.

raster <- raster(matrix(c(1,2,NA, 1,2,3, 1,2,3), nrow = 3, ncol = 3 ))
raster_points <- rasterToPoints(raster, na.rm = FALSE)

Therefore, I put a raster with 200 cells and I get a data.frame with only 150 rows. How can I obtain the point with empty cells in my final data.frame?

You could combine xyFromCell, values, and cbind. This returns the central coordinates of each cell (when you initialized the raster, it assumes a 1 x 1 extent unless defined otherwise) and its value, including NAs, in matrix form:

cbind(xyFromCell(raster, 1:ncell(raster)), values(raster))
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.