Description Usage Arguments Details See Also Examples
Represent an array as columns of dimensional indices and value
1 | indexvalue(x, reverse = FALSE)
|
x |
an array or something that can be coerced into an array |
reverse |
logical; convert from Index–value representation to regular array representation? |
An n-dimensional array will be unfolded to a n+1-column data.frame where the first n columns represent the indices of the n dimensions, and the last column gives the value found at each index tuple. The reverse process can also be performed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | arr <- array(1:(2*3*4), dim=c(2, 3, 4))
arr.is <- indexvalue(arr)
# can be used to permutate an array
indexvalue(arr.is[,c(2, 1, 3, 4)], rev=TRUE)
aperm(arr, c(2, 1, 3))
# can interpret values (symbols) as dimensional indices and permute them as well
arr2 <- array(rep(1:6, 4), dim=c(2, 3, 4))
arr2.is <- indexvalue(arr2)
indexvalue(arr2.is[,c(1, 2, 4, 3)], rev=TRUE)
# a latin square will produce an "orthogonal array"
set.seed(1)
lsq <- latin_sq(5)
iv <- indexvalue(lsq)
iv
# any permutation of a latin square is also a latin square
indexvalue(iv[, c(1, 3, 2)], reverse=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.