Uses a list of the same length as the dimensions of an array to extract information, similar to using matrix indexing.

arrayExtractor(inarray, valslist)

Arguments

inarray

The input array.

valslist

A list of vectors to use to extract data. A value of NULL for any of the list elements will return all values for that dimension.

Value

An array.

Note

The list used for valslist must be the same length as the number of dimensions in the array. It must also be specified in the same order as you would normally reference the dimensions of an array. For instance, in the example, the array has row dimensions, column dimensions, and a third dimension.

References

http://stackoverflow.com/q/34795331/1270695

Author

Ananda Mahto

Examples

my_array <- structure(1:12, .Dim = c(2L, 3L, 2L), .Dimnames = list(c("D_11", "D_12"), c("D_21", "D_22", "D_23"), c("D_31", "D_32"))) my_array
#> , , D_31 #> #> D_21 D_22 D_23 #> D_11 1 3 5 #> D_12 2 4 6 #> #> , , D_32 #> #> D_21 D_22 D_23 #> D_11 7 9 11 #> D_12 8 10 12 #>
arrayExtractor(my_array, list("D_11", NULL, NULL))
#> , , D_31 #> #> D_21 D_22 D_23 #> D_11 1 3 5 #> #> , , D_32 #> #> D_21 D_22 D_23 #> D_11 7 9 11 #>
arrayExtractor(my_array, list(NULL, "D_21", "D_32"))
#> , , D_32 #> #> D_21 #> D_11 7 #> D_12 8 #>
arrayExtractor(my_array, list(NULL, c("D_21", "D_22"), NULL))
#> , , D_31 #> #> D_21 D_22 #> D_11 1 3 #> D_12 2 4 #> #> , , D_32 #> #> D_21 D_22 #> D_11 7 9 #> D_12 8 10 #>