Elementwise difference of numeric or character arrays.

x %diff% y

Arguments

x

numeric or character array.

y

numeric or character array.

Value

array.

References

Guidotti E (2022). "calculus: High-Dimensional Numerical and Symbolic Calculus in R." Journal of Statistical Software, 104(5), 1-37. doi:10.18637/jss.v104.i05

See also

Other basic arithmetic: %div%(), %dot%(), %inner%(), %kronecker%(), %outer%(), %prod%(), %sum%()

Examples

### vector 
x <- c("a+1","b+2")
x %diff% x
#> [1] "0" "0"

### matrix 
x <- matrix(letters[1:4], ncol = 2)
x %diff% x
#>      [,1] [,2]
#> [1,] "0"  "0" 
#> [2,] "0"  "0" 

### array
x <- array(letters[1:12], dim = c(2,2,3))
y <- array(1:12, dim = c(2,2,3))
x %diff% y
#> , , 1
#> 
#>      [,1]      [,2]     
#> [1,] "(a) - 1" "(c) - 3"
#> [2,] "(b) - 2" "(d) - 4"
#> 
#> , , 2
#> 
#>      [,1]      [,2]     
#> [1,] "(e) - 5" "(g) - 7"
#> [2,] "(f) - 6" "(h) - 8"
#> 
#> , , 3
#> 
#>      [,1]       [,2]      
#> [1,] "(i) - 9"  "(k) - 11"
#> [2,] "(j) - 10" "(l) - 12"
#>