Learn R Programming

topolow (version 1.0.0)

calculate_cumulative_distances: 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
)

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 contains summary_data: a data.frame with distances from the specified reference point to all other points, summarized by season and cluster. The columns include season_num, cluster, color, avg_euclidean_dist, count, total_count, and fraction.

  • If reference_row is FALSE, the list contains dist_data: a data.frame with all unique pairwise distances. The columns include year_diff, euclidean_dist, and ref_year.

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

Examples

Run this code
# 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)

Run the code above in your browser using DataLab