Skip to contents

Detection of the closest points to the centroid of a cloud of points

Usage

closest_to_centroid(data, x_column, y_column, space, n = 1, id_column = NULL)

Arguments

data

matrix or data.frame that contains at least two columns.

x_column

(character) the name of the x-axis.

y_column

(character) the name of the y-axis.

space

(character) space in which the thinning will be performed. There are two options available: "G", if it will be in geographic space, and "E", if it will be in environmental space.

n

(numeric) number of points that are close to the centroid to be detected. Default = 1.

id_column

(character or numeric) name or numeric index of the column in data containing identifiers of one or distinct sets of points. If, NULL, the default, only one set is assumed.

Value

A data.frame containing n rows corresponding to the point or points that are the closest to the centroid of all other points of reference.

Examples

# Data
m_matrix <- read_master(system.file("extdata/m_matrix.rds",
                                    package = "biosurvey"))
data1 <- m_matrix$data_matrix

# Finding the closest point to the centroid
centroid <- closest_to_centroid(data1, x_column = "Longitude",
                                y_column = "Latitude", space = "G",
                                n = 1, id_column = NULL)