R/centroid_coords.R

Defines functions centroid_coords

## Function to find centroid coordinates
centroid_coords <- function(x, type = "centroid"){
  # x = data.frame with ordination scores

  ## Mean
  if(type == "centroid"){
    res <- plyr::numcolwise(mean)(x)
  }

  ## Spatial median (minimizes sum of distances of points from it)
  ## in 1d it is equal to the ordinary median (but not in >= 2d)
  if(type == "medoid"){
    res <- vegan:::ordimedian(x, groups = 1)
  }

  return(res)
}
vmikk/metagMisc documentation built on June 20, 2024, 7:20 a.m.