disttools provides the functionality needed to rapidly and intuitively retrieve information from large ‘dist’ objects. This functionality is encoded in the get_dists function. The function’s main use cases are outlined below.
After installing the package, it can be loaded by executing:
Below, some example data is randomly generated.
A ‘dist’ object can be generated for these points by executing:
Below, a set of pairs of points are specified for distance retrieval.
The function get_dists can be used to access the distance between pairs of points. This can be accomplished via two methods. First, a matrix of index pairs can be passed to the function along with the ‘dist’ object itself.
Second, two vectors corresponding to the columns of the index matrix can be passed to the function along with the ‘dist’ object.
Sometimes, the distances for all combinations of a set of points are desired. This information can be easily extracted by executing the following:
It is often desirable to create a matrix or data.frame composed of two columns that indicate the indices being compared and a third column giving the distances between those indices. For convenience, the argument return_indices can be set to TRUE. Doing so results in a three column matrix being returned. It can be converted into a data.frame using the function as.data.frame.
The views expressed are those of the author(s) and do not reflect the official policy of the Department of the Army, the Department of Defense or the U.S. Government.