# expandAsMatrix: expandAsMatrix In edgeR: Empirical Analysis of Digital Gene Expression Data in R

## Description

Expand scalar or vector to a matrix.

## Usage

 `1` ```expandAsMatrix(x, dim=NULL, byrow=TRUE) ```

## Arguments

 `x` scalar, vector, matrix or CompressedMatrix. `dim` integer vector of length 2 specifying the required dimensions of the output matrix. `byrow` logical scalar specifying if matrix should be filled by columns or rows for a vector `x`.

## Details

This function expands a scalar, row/column vector or CompressedMatrix to be a matrix of dimensions `dim`. It is used internally in edgeR to convert offsets, weights and other values to a matrix for consistent handling. If `dim` is `NULL`, the function is equivalent to calling `as.matrix(x)`.

If `x` is a vector, its length must match one of the output dimensions. The matrix will then be filled by repeating the matrix across the matching dimension. For example, if `length(x)==dim`, the matrix will be filled such that each row contains `x`. If both dimensions match, filling is determined by `byrow`, with filling by rows as the default.

If `x` CompressedMatrix object, the size of any non-repeated dimensions must be consistent with corresponding output dimension. The `byrow` argument will be ignored as the repeat specifications will dictate how expansion should be performed. See `?CompressedMatrix` for more details.

## Value

Numeric matrix of dimension `dim`.

Gordon Smyth

## Examples

 ```1 2``` ```expandAsMatrix(1:3,c(4,3)) expandAsMatrix(1:4,c(4,3)) ```

### Example output

```Loading required package: limma
[,1] [,2] [,3]
[1,]    1    2    3
[2,]    1    2    3
[3,]    1    2    3
[4,]    1    2    3
[,1] [,2] [,3]
[1,]    1    1    1
[2,]    2    2    2
[3,]    3    3    3
[4,]    4    4    4
```

edgeR documentation built on Jan. 16, 2021, 2:03 a.m.