Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

aplus

Generalized array addition


Description

Given two arrays a and b with length(dim(a))==length(dim(b)), return a matrix with dimensions pmax(dim(a),dim(b)) where “overlap” elements are a+b, and the other elements are either 0, a, or b according to location. See details section.

Usage

aplus(...)

Arguments

...

numeric or complex arrays

Details

The function takes any number of arguments (the binary operation is associative).

The operation of aplus() is understandable by examining the following pseudocode:

  • outa <- array(0,pmax(a,b))

  • outb <- array(0,pmax(a,b))

  • outa[1:dim(a)] <- a

  • outb[1:dim(a)] <- b

  • return(outa+outb)

See how outa and outb are the correct size and the appropriate elements of each are populated with a and b respectively. Then the sum is returned.

Author(s)

Robin K. S. Hankin

See Also

Examples

aplus(rbind(1:9),cbind(1:9))

a <- matrix(1:8,2,4)
b <- matrix(1:10,5,2)
aplus(a*100,b,b)

magic

Create and Investigate Magic Squares

v1.5-9
GPL-2
Authors
Robin K. S. Hankin
Initial release
2018-09-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.