nearestbyday: Merge two point datasets by day.

Description Usage Arguments Value Examples

Description

Merge point datasets by day to the closest of K nearest neighbors (with an optional distance constraint).

Usage

1
2
3
nearestbyday(jointo.pts, joinfrom.pts, jointo, joinfrom, jointovarname,
  joinfromvarname, joinprefix = "closest", valuefield = "avewsp",
  knearest = 5, maxdistance = NA, nearestmean = FALSE, verbose = FALSE)

Arguments

jointo.pts

points matrix output from makepointsmatrix

joinfrom.pts

points matrix output from makepointsmatrix

jointo

data.table target

joinfrom

data.table data source

jointovarname

column name for unique field for points in jointo

joinfromvarname

column name for unique field for points in joinfrom

joinprefix

string to use as name for new variables

valuefield

column name with field to be merged in

knearest

number of nearest neighbors to check for non-missing data

maxdistance

(optional) constraint on distance, in the units of the points matrix

nearestmean

(optional) also compute mean of knearest values within maxdistance?

verbose

print output of the intermediate data.table size and fields

Value

A data.table, akin to a semi_join on nearest neighbor and day.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
jointo <- data.table(x = 1:5, y = 1:5, siteidx = 1:5,
                    day = as.Date("2004-04-01"))
joinfrom <- data.table(x = rep(1:5 + 0.1, times = 5),
                      y = rep(1:5, each = 5), 
                      siteidy = letters[1:25], # currently this needs to be character
                      value = 100 + 1:25,
                      day = as.Date("2004-04-01"))
                      
jointo.pt <- makepointsmatrix(datatable = jointo, 
                             xvar = "x", yvar = "y", idvar = "siteidx") 
joinfrom.pt <- makepointsmatrix(datatable = joinfrom, 
                               xvar = "x", yvar = "y", idvar = "siteidy") 
joinout <- nearestbyday(jointo.pts = jointo.pt, joinfrom.pts = joinfrom.pt, 
                       jointo = jointo, joinfrom = joinfrom, 
                       jointovarname = "siteidx", joinfromvarname = "siteidy", 
                       joinprefix = "nearest", valuefield = "value", 
                       knearest = 3, maxdistance = 2, 
                       nearestmean = TRUE, verbose = TRUE)
joinout                        

allanjust/aodlur documentation built on May 10, 2019, 9:22 a.m.