api_tabSlice.Rd
Functions for extracting slices of arrays
tabSlice(
tab,
slice = NULL,
margin = names(slice),
drop = TRUE,
as.array = FALSE
)
tabSlice2(tab, slice, margin.idx, drop = TRUE, as.array = FALSE)
tabSlicePrim(tab, slice, drop = TRUE)
tabSliceMult(tab, slice, val = 1, comp = 0)
tabSlice2Entries(tab, slice, complement = FALSE)
An array with named dimnames.
A list defining the slice.
Names of variables in slice.
If TRUE then dimensions with only one level will be dropped from the output.
If the resulting array is one-dimensional the result will by default be a vector with no dim attribute unless as.array is TRUE.
Indec of variables in slice.
The values that entries in the slice will be multiplied with.
The values that entries NOT in the slice will be multiplied with.
If TRUE the complement of the entries are returned.
x = HairEyeColor
s = list(Hair=c("Black", "Brown"), Eye=c("Brown", "Blue"))
s1 = tabSlice(x, slice=s); s1
#> , , Sex = Male
#>
#> Eye
#> Hair Brown Blue
#> Black 32 11
#> Brown 53 50
#>
#> , , Sex = Female
#>
#> Eye
#> Hair Brown Blue
#> Black 36 9
#> Brown 66 34
#>
tabSlice2Entries(x, slice=s)
#> [1] 1 2 5 6 17 18 21 22
tabSlice2Entries(x, slice=s, complement=TRUE)
#> [1] 3 4 7 8 9 10 11 12 13 14 15 16 19 20 23 24 25 26 27 28 29 30 31 32
## tabSliceMult
s2 = tabSliceMult(x, slice=s); s2
#> , , Sex = Male
#>
#> Eye
#> Hair Brown Blue Hazel Green
#> Black 32 11 0 0
#> Brown 53 50 0 0
#> Red 0 0 0 0
#> Blond 0 0 0 0
#>
#> , , Sex = Female
#>
#> Eye
#> Hair Brown Blue Hazel Green
#> Black 36 9 0 0
#> Brown 66 34 0 0
#> Red 0 0 0 0
#> Blond 0 0 0 0
#>
sp = list(c(1,2), c(1,2), TRUE)
tabSlicePrim(x, slice=sp)
#> , , Sex = Male
#>
#> Eye
#> Hair Brown Blue
#> Black 32 11
#> Brown 53 50
#>
#> , , Sex = Female
#>
#> Eye
#> Hair Brown Blue
#> Black 36 9
#> Brown 66 34
#>
tabSlice(x, slice=s)
#> , , Sex = Male
#>
#> Eye
#> Hair Brown Blue
#> Black 32 11
#> Brown 53 50
#>
#> , , Sex = Female
#>
#> Eye
#> Hair Brown Blue
#> Black 36 9
#> Brown 66 34
#>