Array2Matrix: Convert an Array with 4 Dimensions into a Matrix

Description Usage Arguments Value Author(s) See Also Examples

View source: R/gapfill.R

Description

Converts the array, a, with 4 dimensions, c(d1, d2, d3, d4), into a matrix with d1*d2 rows and d3*d4 columns.

Usage

1

Arguments

a

Array with 4 dimensions.

Value

A matrix. If a has the attribute mp, the transformed attribute is returned as well. See ArrayAround for more information about mp.

Author(s)

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

See Also

Index, ArrayAround.

Examples

1
2
3
4
5
6
7
a <- array(data = 1:16, dim = c(2, 2, 2, 2))
Array2Matrix(a = a)
attr(a, "mp") <- c(1, 2, 2, 1)
Array2Matrix(a = a)

Array2Matrix(ArrayAround(data = a, mp = c(1, 1, 1, 1),
                         size = c(1, 1, 2, 2))) 

Example output

Loading required package: ggplot2
     [,1] [,2] [,3] [,4]
[1,]    1    5    9   13
[2,]    2    6   10   14
[3,]    3    7   11   15
[4,]    4    8   12   16
     [,1] [,2] [,3] [,4]
[1,]    1    5    9   13
[2,]    2    6   10   14
[3,]    3    7   11   15
[4,]    4    8   12   16
attr(,"mp")
[1] 3 2
     [,1] [,2] [,3] [,4]
[1,]    1    5    9   13
[2,]    2    6   10   14
[3,]    3    7   11   15
[4,]    4    8   12   16
attr(,"mp")
[1] 1 1

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