circ_minus: Calculate the circular subtraction x - y

View source: R/circular_functions.R

circ_minusR Documentation

Calculate the circular subtraction x - y

Description

Calculate the circular subtraction x - y

Usage

circ_minus(x, y, int, type = c("minusPiPlusPi", "ZeroPlus2Pi"))

Arguments

x

A numeric vector or array.

y

A numeric vector or array.

int

A numeric value. The number of units of x in a full circle, e.g., for unit days: int = 365; for unit months: int = 12.

type

A character string. If type == "minusPiPlusPi", then the resulting value lies between -int / 2 and int / 2. If type == "ZeroPlus2Pi", then the resulting value lies between 0 and int.

Examples

# Days of year
circ_minus(260, 240, int = 365) ## expected: +20
circ_minus(240, 260, int = 365) ## expected: -20
circ_minus(240, 260, int = 365, type = "ZeroPlus2Pi") ## expected: 345
circ_minus(10, 360, int = 365) ## expected: +15
circ_minus(360, 10, int = 365) ## expected: -15
circ_minus(360, 10, int = 365, type = "ZeroPlus2Pi") ## expected: 350
circ_minus(0, 360, int = 365) ## expected: +5
circ_minus(360, 0, int = 365) ## expected: -5
circ_minus(360, 0, int = 365, type = "ZeroPlus2Pi") ## expected: 360

# Matrix examples
x <- matrix(c(260, 240, 10, 360, 0, 360), nrow = 3, ncol = 2)
y <- matrix(c(240, 260, 360, 10, 360, 0), nrow = 3, ncol = 2)
circ_minus(x, y, int = 365)
y2 <- y
y2[1, 1] <- NA
circ_minus(y2, x, int = 365)

DrylandEcology/rSW2utils documentation built on Dec. 9, 2023, 10:44 p.m.