groupdist: Group Spatial Points by Distance

View source: R/groupdist.R

groupdistR Documentation

Group Spatial Points by Distance

Description

This function groups spatial points based on the distance to the next point. If distance is smaller than a threshold, points are considered in the same group. Group number for points outside the threshold is NA. Depending on how many spatial points are in the data frame, runtime might be long.

Usage

groupdist(df, coor = NULL, threshold = NULL, groupvar = NULL)

Arguments

df

df a data frame object.

coor

longitude and latitude of the spatial points in the format of c("lon","lat").

threshold

a distance threshold used to determine if points are in the same group. The format is numeric. Unit is meters.

groupvar

grouping object to stratify spatial points. Recommend to be ID for each individual. If groupvar is not specified, all spatial points processed based on their original sequence.

Value

a list of numbers and NAs indicating whether a set of spatial points are in the same group or not in any groups.

See Also

seqgroup, slide

Examples

data(mobility)
mobility$distgroup<- groupdist(mobility, coor = c("lon", "lat"), threshold = 100, groupvar = "id")


nyu-mhealth/Mobility documentation built on July 4, 2025, 9:54 a.m.