slice: Helper Routine

Description Usage Arguments Value See Also Examples

Description

Slices array by specified dimension.

Usage

1
slice(x, MARGIN, n)

Arguments

x

An array-like object.

MARGIN

An integer giving the dimension to slice by.

n

Number of slice.

Value

Returns array of dimensions dim(x)[-MARGIN]. The corresponding dimnames are preserved.

See Also

slice.index.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
  x <- 1:10
  slice(x, 1, 1)

  x <- matrix(1:4, 2, 2)
  rownames(x) <- c("Row 1", "Row 2")
  colnames(x) <- c("Col 1", "Col 2")
  x
  slice(x, 1, 1)
  slice(x, 1, 2)
  slice(x, 2, 1)
  slice(x, 2, 2)

  x <- array(1:24, dim = c(2, 3, 4))
  dimnames(x) <- list(letters[1:2], letters[3:5], letters[6:9])
  x
  slice(x, 1, 1) 
  slice(x, 2, 1)
  slice(x, 3, 1)

cmrutils documentation built on Sept. 3, 2018, 5:03 p.m.

Related to slice in cmrutils...