powered by
Construct a matrix with ones at and below the given diagonal and zeros elsewhere.
tri(nrow, ncol = nrow, k = 0, diag = TRUE)
The desired number of rows.
The desired number of columns.
The sub-diagonal at and below which the matrix is filled. k = 0 is the main diagonal, while k < 0 is below it, and k > 0 is above. The default is 0.
k = 0
k
Logical indicating whether to include the diagonal. Default is TRUE.
TRUE
tri(5, 5) tri(5, 5, 2) tri(5, 5, -1)
Run the code above in your browser using DataLab