% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/R-trajectory.R
\name{compute_centroids}
\alias{compute_centroids}
\title{Compute cluster centroids (mean x/y per cluster)}
\usage{
compute_centroids(df)
}
\arguments{
\item{df}{A `data.frame` containing at least the columns `cluster`, `x`, and
`y`.
`cluster` can be any type accepted by `aggregate()` grouping (e.g., integer,
  factor, character). `x` and `y` must be numeric.}
}
\value{
A `data.frame` with one row per cluster and columns:
\describe{
  \item{cluster}{Cluster identifier.}
  \item{x}{Mean x-coordinate for the cluster.}
  \item{y}{Mean y-coordinate for the cluster.}
}
}
\description{
Computes the centroid of each cluster by taking the mean of the `x` and `y`
coordinates for each `cluster` level.
}
\details{
This is a thin wrapper around \code{\link[stats:aggregate]{aggregate}} using
\code{FUN = mean}. Missing values are handled according to `mean()`'s default
behavior (i.e., `NA`s will propagate unless you pre-handle them).
}
\examples{
df <- data.frame(
  cluster = c(1, 1, 2, 2),
  x = c(0, 2, 10, 12),
  y = c(1, 3, 5, 7)
)
compute_centroids(df)

}
