```
# NOT RUN {
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
lidar = readLAS(LASfile)
# Canopy surface model with 4 m^2 cells
grid_metrics(lidar, max(Z), 2) %>% plot
# Mean height with 400 m^2 cells
grid_metrics(lidar, mean(Z), 20) %>% plot
# Define your own new metrics
myMetrics = function(z, i)
{
metrics = list(
zwimean = sum(z*i)/sum(i), # Mean elevation weighted by intensities
zimean = mean(z*i), # Mean products of z by intensity
zsqmean = sqrt(mean(z^2)) # Quadratic mean
)
return(metrics)
}
metrics = grid_metrics(lidar, myMetrics(Z, Intensity))
plot(metrics)
plot(metrics, "zwimean")
plot(metrics, "zimean")
plot(metrics, "zsqmean")
#etc.
# }
```

Run the code above in your browser using DataLab