Learn R Programming

spatialEco (version 2.0-1)

idw.smoothing: Inverse Distance Weighted smoothing

Description

Distance weighted smoothing of a variable in a spatial point object

Usage

idw.smoothing(x, y, d, k)

Value

A vector, same length as nrow(x), of smoothed y values

Arguments

x

An sf POINT class object

y

Numeric data column in x to be smoothed

d

Distance constraint

k

Maximum number of k-nearest neighbors within d

Examples

Run this code

library(sf)
if(require(sp, quietly = TRUE)) {
  data(meuse, package = "sp")
  meuse <- st_as_sf(meuse, coords = c("x", "y"), crs = 28992, 
                    agr = "constant")
}
      
 # Calculate distance weighted mean on cadmium variable in meuse data   
   cadmium.idw <- idw.smoothing(meuse, 'cadmium', k=nrow(meuse), d = 1000)                
   meuse$cadmium.wm <- cadmium.idw
 
   opar <- par(no.readonly=TRUE)
     par(mfrow=c(2,1)) 
       plot(density(meuse$cadmium), main='Cadmium')
       plot(density(meuse$cadmium.wm), main='IDW Cadmium')
   par(opar)

plot(meuse[c("cadmium","cadmium.wm")], pch=20)   

Run the code above in your browser using DataLab