create_distance_matrix | R Documentation |
This function can create distance matrix from data frame with proper structure.
create_distance_matrix(df)
df |
data frame including cases (point1,point2,distance) |
Distances between points should be defined in form of distance matrix (see vignette for package for details). create_distance_matrix() function uses as an input data frame for which every row includes case: ("pointX","pointY", distance_between_them). As an output proper distance matrix is generated.
Format of input data frame:
Format 1
first column - numeric
second column - numeric
third column - numeric
For such case we assume that n points are enumerated by integers 1 .. n and first two columns include those indexes.
Format 2
first column - character
second column - character
third column - numeric
For such case we are using points names instead of indexes. All used names are sorted and than indexes (used in output distance matrix) will be assigned to following points.
When input data frame is not complete (not all possible distances are described) missing cases will be marked in distance matrix as NA.
create_distance_matrix() secures first and second metrics rule (see vignette for package) so even if this info is not included in input df output dm will include 0 in diagonal. When there are many (different) distances for the same points in data frame, output distance matrix will include only last (for both (i,j) and (j,i) cases - so second metrics rule is fulfilled).
distance matrix
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.