calculate_cumulative_distances {topolow} | R Documentation |
Calculate Cumulative Distance Metrics
Description
Calculates cumulative distance metrics either from a reference point or between all pairs. Handles both seasonal and year-based analyses.
Usage
calculate_cumulative_distances(
df_coords,
ndim,
reference_row = FALSE,
na.rm = TRUE
)
Arguments
df_coords |
Data frame containing: - V1...Vn coordinate columns - year: Numeric years - season: Character season identifiers. - cluster: Factor cluster assignments - color: Character color codes |
ndim |
Number of coordinate dimensions |
reference_row |
Integer index of reference row (or FALSE for all-pairs analysis) |
na.rm |
Logical indicating whether to remove NA values |
Value
A list containing the calculated distance metrics. The content of the list depends
on the reference_row
parameter.
If
reference_row
is specified, the list containssummary_data
: adata.frame
with distances from the specified reference point to all other points, summarized by season and cluster. The columns includeseason_num
,cluster
,color
,avg_euclidean_dist
,count
,total_count
, andfraction
.If
reference_row
isFALSE
, the list containsdist_data
: adata.frame
with all unique pairwise distances. The columns includeyear_diff
,euclidean_dist
, andref_year
.
Examples
# Create sample coordinate data
coords <- data.frame(V1 = rnorm(10), V2 = rnorm(10), year = rep(2000:2004, 2),
season = paste0(rep(2000:2004, 2), "-S"),
cluster = factor(rep(1:2, 5)), color = "blue")
# Calculate distances from reference point
ref_distances <- calculate_cumulative_distances(coords, ndim=2, reference_row=1)
# Calculate all pairwise distances
all_distances <- calculate_cumulative_distances(coords, ndim=2, reference_row=FALSE)