Index: Index Conversions

Description Usage Arguments Value Author(s) Examples

Description

Converts an index from the first length to the second length. For example, assume that c(2, 2) indexes an element in a matrix with 2 rows and 5 columns. If the matrix is transformed to a vector, the same element can be accessed with the index IndexTwoOne(c(2, 2), c(2, 5)) (=4).

Usage

1
2
3
IndexTwoOne(index, dimTwo)

IndexOneFour(index, dimFour)

Arguments

index

Integer vector of length 2 for IndexTwoOne() and length 1 for IndexOneFour().

dimTwo

Integer vector of length 2 indicating the dimension of the 2 dimensional array.

dimFour

Integer vector of length 4 indicating the dimension of the 4 dimensional array.

Value

Vector of length 1 for IndexTwoOne() and length 4 for IndexOneFour().

Author(s)

Florian Gerber, flora.fauna.gerber@gmail.com.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## IndexTwoOne
IndexTwoOne(c(2, 2), c(2, 5))
v <- 1:10
dimTwo <- c(2, 5)
m <- array(v, dimTwo)
stopifnot(v[IndexTwoOne(c(2, 2), dimTwo)] == m[2,2])

 
## IndexOneFour
IndexOneFour(13, c(2, 2, 2, 2))
w <- 1:16
dimFour <- c(2, 2, 2, 2)
a <- array(w, dimFour)
stopifnot(a[1,1,2,2] == w[13])

gapfill documentation built on Feb. 12, 2021, 5:06 p.m.