circularize2dist: circularize2dist

View source: R/circularize2dist.r

circularize2distR Documentation

circularize2dist

Description

Circularizes a vector into a dist object. For example, a vector of days of the year, where the distance between 365 and 2 should be less than the distance between 350 and 365. Another example may be direction, where 0.1 and 2pi radians are close together.

Usage

circularize2dist(x, maxx)

Arguments

x

a numeric vector. All values should be >0.

maxx

the maximum theoretical value (also the zero value!) of variable x. In the exampe of months of the year, maxx would be 12, even if you only had data for months 1-8. For degrees, maxx=360. For radians, maxx=2*pi. Must be greater than or equal to values of x.

Value

a vector of differences, ordered identically to a "dist" object.

Author(s)

John L. Darcy

Examples

# library(specificity)
# # make some fake data to represent months of the year
# months <- c(1, 4, 11)
# # run circularize2dist() on the months. Must specify that
# # maxx = 12, since december is both 12 and 0 for these data.
# circularize2dist(months, 12)
# # output is a distance matrix. 
# # rows and cols of months_circdm are months - it's ordered.
# # notice the distance between 11 and 1 is 2, not 10!


darcyj/specificity documentation built on Aug. 1, 2023, 8 a.m.