Addition, subtraction etc. of arrays

a1 %a+% a2

a1 %a-% a2

a1 %a*% a2

a1 %a/% a2

a1 %a/0% a2

tab1 %a_% marg

tab1 %a==% tab2

tab1 %a^% extra

tab1 %aperm% perm

tab1 %aalign% tab2

tab1 %aslice% slice

tab1 %aslice*% slice

tab1 %amarg% marg

Arguments

tab1, tab2

Multidimensional arrays with named dimnames (we call them 'named arrays').

marg

A vector of indices or dimnames or a right hand sided formula giving the desired marginal.

extra

List defining the extra dimensions.

perm

A vector of indices or dimnames or a right hand sided formula giving the desired permutiation.

slice

A list of the form name=value.

a, a1, a2

Arrays (with named dimnames)

Author

Søren Højsgaard, sorenh@math.aau.dk

Examples

hec <- HairEyeColor
a1 <- tabMarg(hec, c("Hair", "Eye"))
a2 <- tabMarg(hec, c("Hair", "Sex"))
a3 <- tabMarg(hec, c("Eye", "Sex"))

## Binary operations
a1 %a+% a2
#> , , Sex = Male
#> 
#>        Hair
#> Eye     Black Brown Red Blond
#>   Brown   124   262  60    53
#>   Blue     76   227  51   140
#>   Hazel    71   197  48    56
#>   Green    61   172  48    62
#> 
#> , , Sex = Female
#> 
#>        Hair
#> Eye     Black Brown Red Blond
#>   Brown   120   262  63    88
#>   Blue     72   227  54   175
#>   Hazel    67   197  51    91
#>   Green    57   172  51    97
#> 
a1 %a-% a2
#> , , Sex = Male
#> 
#>        Hair
#> Eye     Black Brown Red Blond
#>   Brown    12   -24  -8   -39
#>   Blue    -36   -59 -17    48
#>   Hazel   -41   -89 -20   -36
#>   Green   -51  -114 -20   -30
#> 
#> , , Sex = Female
#> 
#>        Hair
#> Eye     Black Brown Red Blond
#>   Brown    16   -24 -11   -74
#>   Blue    -32   -59 -20    13
#>   Hazel   -37   -89 -23   -71
#>   Green   -47  -114 -23   -65
#> 
a1 %a*% a2
#> , , Sex = Male
#> 
#>        Hair
#> Eye     Black Brown Red Blond
#>   Brown  3808 17017 884   322
#>   Blue   1120 12012 578  4324
#>   Hazel   840  7722 476   460
#>   Green   280  4147 476   736
#> 
#> , , Sex = Female
#> 
#>        Hair
#> Eye     Black Brown Red Blond
#>   Brown  3536 17017 962   567
#>   Blue   1040 12012 629  7614
#>   Hazel   780  7722 518   810
#>   Green   260  4147 518  1296
#> 
a1 %a/% a2
#> , , Sex = Male
#> 
#>        Hair
#> Eye          Black     Brown       Red     Blond
#>   Brown 1.21428571 0.8321678 0.7647059 0.1521739
#>   Blue  0.35714286 0.5874126 0.5000000 2.0434783
#>   Hazel 0.26785714 0.3776224 0.4117647 0.2173913
#>   Green 0.08928571 0.2027972 0.4117647 0.3478261
#> 
#> , , Sex = Female
#> 
#>        Hair
#> Eye          Black     Brown       Red      Blond
#>   Brown 1.30769231 0.8321678 0.7027027 0.08641975
#>   Blue  0.38461538 0.5874126 0.4594595 1.16049383
#>   Hazel 0.28846154 0.3776224 0.3783784 0.12345679
#>   Green 0.09615385 0.2027972 0.3783784 0.19753086
#>