circ_add: Calculate the circular addition x + y

View source: R/circular_functions.R

circ_addR Documentation

Calculate the circular addition x + y

Description

Calculate the circular addition x + y

Usage

circ_add(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

# Matrix examples: day of year
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_add(x, y, int = 365)
circ_add(x, y, int = 365, type = "ZeroPlus2Pi")

# Circular addition and subtraction
r1 <- circ_add(circ_minus(x, y, int = 365), y, int = 365)
r2 <- circ_minus(circ_add(x, y, int = 365), y, int = 365)
all.equal(r1, r2)

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