View source: R/circularize2dist.r
circularize2dist | R Documentation |
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.
circularize2dist(x, maxx)
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. |
a vector of differences, ordered identically to a "dist" object.
John L. Darcy
# 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!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.