operators: FLQuant arithmetic operators that extend objects

%+%R Documentation

FLQuant arithmetic operators that extend objects

Description

Arithmetic operations between two FLQuant objects using the standars operators (+, -, *, /, ^, see Arith) need all dimensions in both objects to match. This requirement is relaxed by using the percent version of those five operators: ⁠%+%⁠, ⁠%-%⁠, %*%, %/% and ⁠%^%⁠.

Usage

e1 %+% e2

x %-% y

x %^% y

## S4 method for signature 'FLQuant,FLQuant'
x %*% y

## S4 method for signature 'FLQuant,FLQuant'
e1 %/% e2

## S4 method for signature 'FLQuant,FLQuant'
e1 %+% e2

## S4 method for signature 'FLQuant,FLQuant'
x %-% y

## S4 method for signature 'FLQuant,FLQuant'
x %^% y

## S4 method for signature 'FLPar,FLQuant'
x %*% y

## S4 method for signature 'FLPar,FLQuant'
e1 %/% e2

## S4 method for signature 'FLPar,FLQuant'
e1 %+% e2

## S4 method for signature 'FLPar,FLQuant'
x %-% y

## S4 method for signature 'FLPar,FLQuant'
x %^% y

## S4 method for signature 'FLQuant,FLPar'
x %*% y

## S4 method for signature 'FLQuant,FLPar'
e1 %/% e2

## S4 method for signature 'FLQuant,FLPar'
e1 %+% e2

## S4 method for signature 'FLQuant,FLPar'
x %-% y

## S4 method for signature 'FLQuant,FLPar'
x %^% y

## S4 method for signature 'FLPar,FLPar'
x %*% y

## S4 method for signature 'FLPar,FLPar'
e1 %+% e2

## S4 method for signature 'FLPar,FLPar'
x %-% y

## S4 method for signature 'FLPar,FLPar'
e1 %/% e2

## S4 method for signature 'FLPar,FLPar'
x %^% y

## S4 method for signature 'FLQuants,FLPar'
e1 / e2

## S4 method for signature 'FLQuants,FLPar'
e1 * e2

## S4 method for signature 'FLQuants,FLPars'
e1 / e2

## S4 method for signature 'FLQuants,FLPars'
e1 * e2

## S4 method for signature 'FLQuants,FLQuants'
e1 / e2

## S4 method for signature 'FLQuants,FLQuants'
e1 * e2

## S4 method for signature 'FLQuants,FLQuants'
e1 + e2

## S4 method for signature 'FLQuants,FLQuants'
e1 - e2

Details

If any of the objects is of length one in a dimensions where the other is longer, the dimensions will be extended and the element-by-element operation then conducted. Dimensions and dimnames of the output will be those of the larger object. See the examples to observe their behaviour.

Please note that this behaviour is already present on the Arith methods for FLArray-derived classes but only on the 6th, iter, dimension.

The original use of the %*% operator, as vector product, is not available for FLQuant objects, but can be applied to the array inside them, as in the example below.

Methods for operations between an FLQuant and an FLPar object will match dimensions by names of dimnames, regardless of position.

Generic function

x %+% y, x %-% y, x %*% y, e1 %/% e2, x %^% y

Author(s)

The FLR Team

See Also

FLQuant, matmult

Examples


a <- FLQuant(2, dim=c(3,3,2))
b <- FLQuant(3, dim=c(3,3,1))

# This should fail
## Not run:  a * b 

a %*% b
a %+% b
# To use base's %*% vector product, apply it to a matrix from @.Data
b@.Data[,,,,,] %*% 1:3
# or
b[,,drop=TRUE] %*% 1:3

# FLPar vs. FLQuant works by dimnames' names
flp <- FLPar(2, dimnames=list(params='a', year=2000:2005, iter=1))
flq <- FLQuant(3, dimnames=list(year=2000:2005))
flp %*% flq

# Divide each FLQuants element by a 'param' in FLPar, e.g. time series
# divide by reference points
FLQuants(SSB=FLQuant(2303), F=FLQuant(0.8)) / FLPar(SSB=1560, F=0.4)

# Product of each FLQuants element by a 'param' in FLPar
FLQuants(SSB=FLQuant(2303), F=FLQuant(0.8)) * FLPar(SSB=1560, F=0.4)
# Divide each FLQuants element by each in FLPars
FLQuants(A=FLQuant(2303), B=FLQuant(1287)) /
  FLPars(A=FLPar(SBMSY=1560), B=FLPar(SBMSY=1000))
# Divide each FLQuants element by each in FLPars
FLQuants(A=FLQuant(2303), B=FLQuant(1287)) *
  FLPars(A=FLPar(SBMSY=1560), B=FLPar(SBMSY=1000))
# Divide each FLQuants element by each in FLPars
FLQuants(A=FLQuant(300), B=FLQuant(200)) /
  FLQuants(A=FLQuant(3), B=FLQuant(2))
# Divide each FLQuants element by each in FLPars
FLQuants(A=FLQuant(100), B=FLQuant(200)) *
  FLQuants(A=FLQuant(3), B=FLQuant(2))
# Divide each FLQuants element by each in FLPars
FLQuants(A=FLQuant(100), B=FLQuant(200)) *
  FLQuants(A=FLQuant(3), B=FLQuant(2))
# Divide each FLQuants element by each in FLPars
FLQuants(A=FLQuant(100), B=FLQuant(200)) *
  FLQuants(A=FLQuant(3), B=FLQuant(2))

flr/FLCore documentation built on May 4, 2024, midnight