I'm using the lidR package to calculate LiDAR grid metrics (p.18 documentation) for forestry applications. For example, the following calculates the mean elevation within a 20m cell:
library(lidR)
LASfile <- "/Users/aaron/Desktop/data/1958-08-53.laz"
lidar <- readLAS(LASfile)
l <- grid_metrics(lidar, mean(Z), 20)
I can plot the results using the following approach:
grid_metrics(lidar, mean(Z), 20) %>% plot
What is the proper method to write the grid metrics to a georeferenced raster (e.g. geotiff)?