makeuppertri: Make an upper triangular matrix

Description Usage Arguments Note Examples

View source: R/makeuppertri.R

Description

Upper triangular matrix making made easy.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
makeuppertri(
  entries,
  row,
  col,
  blanks = 0,
  byRow = TRUE,
  incDiag = FALSE,
  nrow = NULL,
  ncol = NULL
)

makeuppertri.list(
  entries,
  len,
  row,
  col,
  blanks = list(),
  byRow = TRUE,
  incDiag = FALSE,
  nrow = NULL,
  ncol = NULL
)

Arguments

entries

Vector of entries for the upper triangular part of the matrix.

row

Number of rows in the matrix

col

Number of columns in the matrix

blanks

What should go in the non-diagonal entries?

byRow

Logical; read the entries by row (as if you're reading) (TRUE), or read in vertically (FALSE).

incDiag

Should the entries go on the diagonal too? TRUE if so, FALSE if not.

nrow, ncol

When I first made this function, I used row and col, but I should have called them nrow and ncol. Hence this addition.

len

Vector of positive integers which specify the lengths of the individual vectors that are pooled in entries.

Note

Use makeuppertri to make a matrix. If you want entries to be vectors (which would have to be an array with list entries), use makeuppertri.list.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Square matrices
makeuppertri(1:choose(5,2), 5, 5)
makeuppertri(1:choose(6,2), 5, 5, incDiag = TRUE)

## Not square.
makeuppertri(1:9, row = 2, col = 5, incDiag = TRUE)
makeuppertri(1:3, row = 5, col = 3)
## List entries
(M <- makeuppertri.list(1:12, c(1, 10, 1), 3, 3))
M[1, 2]   # A list of length one.
M[1, 3]   # Another list of length one.
(M <- makeuppertri.list(1:3, rep(1,3), 3, 3))
M[1, 2]   # Still a list of length one.

vincenzocoia/copsupp documentation built on Aug. 23, 2020, 7:37 a.m.