```
# NOT RUN {
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
lidar = readLAS(LASfile)
# Maximum elevation with a resolution of 4 m
grid_hexametrics(lidar, max(Z), 4) %>% plot
# Mean height with a resolution of 20 m
grid_hexametrics(lidar, mean(Z)) %>% 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_hexametrics(lidar, myMetrics(Z, Intensity), 10)
plot(metrics, "zwimean")
plot(metrics, "zimean")
plot(metrics, "zsqmean")
#etc.
# }
```

Run the code above in your browser using DataLab