Learn R Programming

swaRm (version 0.6.0)

centroid: Centroid

Description

This function computes the centroid (or center of mass) of a set of x-y (or longitude-latitude) coordinates.

Usage

centroid(x, y, robust = FALSE, geo = FALSE)

Value

A two-element list corresponding to the location of the centroid.

Arguments

x

A vector of x (or longitude) coordinates.

y

A vector of y (or latitude) coordinates.

robust

A logical value indicating whether to compute the centroid as a simple average of the coordinates (FALSE, the default), or as the average of the coordinates weighted by the inverse of their mean pairwise distance to all other coordinates in the set (TRUE).

geo

A logical value indicating whether the locations are defined by geographic coordinates (pairs of longitude/latitude values). Default: FALSE.

Author

Simon Garnier, garnier@njit.edu

See Also

dist2centroid

Examples

Run this code
x <- rnorm(25)
y <- rnorm(25, sd = 3)
centroid(x, y)

Run the code above in your browser using DataLab