Array slices

Share:

Description

Functions for extracting slices of arrays

Usage

1
2
3
4
5
6
7
8
arslice(tab, slice = NULL, margin = names(slice), drop = TRUE,
  as.array = FALSE)

arslice_prim(tab, slice, drop = TRUE)

arslice_mult(tab, slice, val = 1, comp = 0)

arslice_entries(tab, slice, complement = FALSE)

Arguments

tab

An array with named dimnames.

slice

A list defining the slice.

margin

Names of variables in slice.

drop

If TRUE then dimensions with only one level will be dropped from the output.

as.array

If the resulting array is one-dimensional the result will by default be a vector with no dim attribute unless as.array is TRUE.

val

The values that entries in the slice will be multiplied with.

comp

The values that entries NOT in the slice will be multiplied with.

complement

If TRUE the complement of the entries are returned.

Author(s)

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

See Also

arperm, armarg, armult, ardiv, aradd, arsubt, arsum, arprod

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
x = HairEyeColor
s = list(Hair=c("Black","Brown"), Eye=c("Brown", "Blue"))

## arslice
s1 = arslice(x, slice=s)
s1

## arslice_entries
arslice_entries(x, slice=s)
arslice_entries(x, slice=s, complement=TRUE)

## arslice_mult
s2 = arslice_mult(x, slice=s)
s2

## arslice_prim does the same as arslice - faster, but the function is less
# flexible
sp = list(c(1,2), c(1,2), TRUE)
arslice_prim(x, slice=sp)
arslice(x, slice=s)
if ( require(microbenchmark) ){
  microbenchmark(arslice_prim(x, slice=sp), arslice(x, slice=s))
}

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.