# How to incorporate stdmetrics in gridmetrics function?

I am attempting to feed the `lidR` gridmetrics function a list of metrics. I can generate the list of metrics within a function (following this example):

``````myMetrics = function(z, i)
{
metrics = list(
zmean   = mean(z),
imean   = mean(i),
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)
}
``````

And then feed the list into the `gridmetrics` function:

``````metrics = grid_metrics(lidar, myMetrics(Z, Intensity), 20)
``````

However, I cannot find a way to incorporate individual stdmetrics into the above `myMetrics` function.

How, for example, would I add the `zqx` or `zkurt` metrics (from this source) into the `myMetrics` function, which can then be fed into the `gridmetrics` function?

You can use the function `stdmetrics` inside your custom function like in the following example (using `stdmetrics_z`)

``````myMetrics = function(z, i)
{
lidrmetrics = stdmetrics_z(z)

mymetrics = 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(c(mymetrics, lidrmetrics))
}

metrics = grid_metrics(lidar, myMetrics(Z, Intensity))
``````

Of course if the function requires more inputs you must update the parameters of your custom function. This is documented in the examples of `help("stdmetrics")`.

Also the following works too.

``````metrics = grid_metrics(lidar, c(myMetrics(Z, Intensity), stdmetrics_z(Z)))
``````
• When I include `lidrmetrics = stdmetrics_z(z)` in the `myMetrics` function, there is no resulting column in the gridmetrics results. Also, how would I incorporate a metric such as `zkurt` from stdmetrics? – Aaron Feb 17 '18 at 16:38
• Did you miss to update the function `return`? This code does work to me. – JRR Feb 19 '18 at 14:44