matrixNew: Generate random/diagonal/zeros/ones Matrix

View source: R/matrixNew.R

matrixNewR Documentation

Generate random/diagonal/zeros/ones Matrix

Description

Generate random/diagonal/zeros/ones matrix, the default is 3 by 3 matrix of 0.

Usage

matrixNew(
  m = 3,
  n = NULL,
  x = 0,
  diagonal = FALSE,
  distr = NULL,
  dimnames = NULL
)

Arguments

m

Number of rows.

n

Number of columns. If n = NULL, then n = m.

x

The value filling in the matrix .

diagonal

Logical, only diagonal remains if TRUE

distr

Distribution functions, e.g. rnorm, rt, runif, etc. If distr is provided, then x will be masked.

dimnames

A dimnames attribute for the matrix: NULL or a list of length 2 giving the row and column names, respectively.

Value

A random/diagonal/zeros/ones Matrix.

See Also

matrixRep

Examples

{
## Not run: 
# The zeros/ones matrix
matrixNew(4) # zeros of 4 by 4 matrix
matrixNew(4, 5) # 4 by 5
matrixNew(x = 1) # ones of 3 by 3 matrix

# The eye/diagonal matrix
matrixNew(m = 3, x = 1, diagonal = TRUE)
matrixNew(m = 5, n = 3, x = 1, diagonal = TRUE)
matrixNew(m = 3, x = 4, diagonal = TRUE)

# The random matrix
matrixNew(m = 4, n = 5, distr = rnorm, dimnames = list(letters[1:4], letters[1:5]))
matrixNew(m = 4, n = 5, distr = rnorm, diagonal = TRUE)

## End(Not run)
}

paodan/funcTools documentation built on April 1, 2024, 12:01 a.m.