rray_arith: Arithmetic operations

Description Usage Arguments Details Value Examples

Description

These functions provide the implementations for their underlying infix operators (i.e. rray_add() powers +). All operators apply broadcasting to their input.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
x %b+% y

rray_add(x, y)

x %b-% y

rray_subtract(x, y)

x %b*% y

rray_multiply(x, y)

x %b/% y

rray_divide(x, y)

x %b^% y

rray_pow(x, y)

rray_identity(x)

rray_opposite(x)

Arguments

x, y

A pair of vectors.

Details

In case you want to apply arithmetic operations with broadcasting to purely base R objects using infix operators, custom infix functions have been exported, such as %b+%, which will perform addition with broadcasting no matter what type the input is.

Value

The value of the arithmetic operation, with dimensions identical to the common dimensions of the input.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library(magrittr)

x <- rray(1:8, c(2, 2, 2)) %>%
  rray_set_row_names(c("r1", "r2")) %>%
  rray_set_col_names(c("c1", "c2"))

y <- matrix(1:2, nrow = 1)

# All arithmetic functions are applied with broadcasting
rray_add(x, y)

# And the power `+` when any underlying input
# is an rray
x + y

# If you happen to only have base R matrices/arrays
# you can use `rray_add()` or `%b+%` to get the
# broadcasting behavior
rray_add(y, matrix(1:2))

y %b+% matrix(1:2)

rray documentation built on July 23, 2019, 5:04 p.m.