calckernel | R Documentation |
This function returns the sum of the product of each cell in the kernel and the corresponding cell in the matrix around the focal cell.
## S3 method for class 'grid'
calckernel(obj, kernel, x, y, row=y2r(y, list=obj), col=x2c(x, list=obj), ...)
## S3 method for class 'matrix'
calckernel(obj, kernel, row, col, use.old=FALSE, ...)
calckernel(obj, ...)
calc.kernel(obj, ...) # depreciated
obj |
either a matrix or an object of class "grid" containing the data |
kernel |
the kernel. It should be a square, odd dimensioned, numeric matrix that sums to 1. |
row, col |
the row and column of the focal cell. The center of the kernel will be aligned with this cell. |
x, y |
the x and y coordinates in map units of the focal cell. |
use.old |
if |
... |
Arguments to be passed to methods |
this function returns the sum of the product of the kernel and data around the focal cell. If (as required)
the kernel sums to one this is the weighted average of the cells.
If the kernel overlaps the edge or obj
contains NA
values than only the available data will be used and the
kernel will be renormalized such that the sum of the used cells is one; the result will be the weighted average of the available data.
A weighted average of the cells in the matrix surrounding the focal cell.
Please make sure the kernel sums to 1. This could be done in the function but
that would be inefficient in cases where the kernel is repeatedly applied to
the matrix. Use kernel <- kernel/sum(kernel, na.rm = TRUE)
to properly
normalize a kernel. If the kernel doesn't sum to one than the results near
edges and NA
values will be inconsistent.
Ethan Plunkett
kernelsmooth
, makegaussiankernel
m <- matrix(1:60, 6, 10)
k <- matrix(1, 3, 3)
k[2,2] <- 4
k <- k/sum(k)
kernelsmooth(m, k)
calckernel(m, k, 2, 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.