Skip to content
Prev 170186 / 398502 Next

Efficent way to create an nxn upper triangular matrix of one's

Here is a way to do this:

round(upper.tri(matrix(1, 9, 9)))

Or if you also need the diagonal of one's

round(upper.tri(matrix(1, 9, 9), diag = TRUE))

-Christos