as_kde {weird} | R Documentation |
Convert data frame or matrix object to kde class
Description
A density specified as a data frame or matrix can be converted to a kde object.
This is useful for plotting the density using autoplot.kde
.
As kde objects are defined on a grid, the density values are interpolated
based on the points in the data frame or matrix.
Usage
as_kde(object, density_column, ngrid, ...)
Arguments
object |
Data frame or matrix with numerical columns, where one column
(specified by |
density_column |
Name of the column containing the density values, specified as a bare expression. If missing, the last column is used. |
ngrid |
Number of points to use for the grid in each dimension. Default is 10001 for univariate densities and 101 for multivariate densities. |
... |
Additional arguments are ignored. |
Value
An object of class "kde"
Author(s)
Rob J Hyndman
Examples
tibble(y = seq(-4, 4, by = 0.01), density = dnorm(y)) |>
as_kde()