I've moved over to version 2 of the lidR package. In previous versions, the output of grid_metrics
was a data.frame
. In version 2.0, the outputs are stored in raster
format. I have additional code, such as running a PCA that works with the metrics in a data.frame
.
Is there a suggested method for converting the raster
products back into a data.frame
?
Best Answer
Make a sample raster:
make two more and make a stack with names:
Now convert to data frame:
Note that
rasterToPoints
does a similar thing, but returns a matrix:but if all values are NA that point is omitted from the output.
as.data.frame
preserves all points:Make first pixel NA in all layers:
Then:
compare: