Learn R Programming

smint (version 0.4.2)

closest: Find closest point(s) in a design or object.

Description

Find closest point(s) in a design matrix or object.

Usage

closest(X, XNew, ...)

Arguments

X
A matrix containing design points as rows or a "Grid" object.
XNew
A vector or matrix containing one or several 'new' design points.
...
Other arguments for methods.

Value

A list with elements
index
Integer vector with length equal to the number of 'new' points. Contains the index of the closest point in X.
value
Matrix with one row for each 'new' design point containing the closest point as found in X.
dist
Numeric vector with length equal to the number of 'new' points. Contains the minimal distances.

Details

When X has class "Grid" weighting the factors has no impact on the (or a) closest point since for each factor there is normally one (and possibly two) level value(s) which minimises the distance to the corresponding value in the given new point (row) of XNew.

Examples

Run this code
## levels at 0, 0.2, 0.4, 0.6, 0.8, 1.0
g <- Grid(nlevels = c("x" = 6, "y" = 6, "z" = 6))
XNew <- c(0.51, 0.61, 0.23)
closest(X = g, XNew = XNew)
X <- as.matrix(g)
closest(X = X, XNew = XNew)

Run the code above in your browser using DataLab