This function enforces uniqueness in numeric data structures of dimension one, two, or three by applying minimal perturbations to duplicated values. It is primarily intended to avoid degeneracy issues (e.g., duplicated coordinates or time stamps) in spatial and spatio-temporal modeling.
make_unique_by_structure(M)If M is a vector, a numeric vector of the same length is returned.
If M is a matrix or data frame, a numeric matrix with the same
dimensions is returned, with standardized column names:
"t" (1D), "x", "y" (2D), or "x", "y", "t" (3D).
A numeric vector, matrix, or data frame with 1, 2, or 3 columns.
For matrices or data frames, columns are interpreted as spatial
(x, y) and optional temporal (t) coordinates.
Depending on the dimensionality of the input, uniqueness is enforced as follows:
1D: duplicated values are slightly perturbed to ensure uniqueness;
2D: duplicated \((x, y)\) coordinate pairs are resolved by perturbing the second coordinate;
3D: duplicated \((x, y)\) pairs and duplicated temporal coordinates are handled separately, ensuring uniqueness in both space and time.
The perturbation magnitude is proportional to machine precision and the scale of the input data, ensuring numerical stability while preserving the original structure as closely as possible.
This function is designed as a low-level utility for preprocessing spatial or spatio-temporal inputs prior to kernel-based local regression or distance computations, where duplicated locations or timestamps may cause numerical singularities.