Index {gapfill}R Documentation

Index Conversions

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

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

## 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])


[Package gapfill version 0.9.6-1 Index]