nymuffin
nymuffin

Reputation: 77

Creating a non-symmetric matrix of 1s with non-symmetric diagonal of 0s in R

EDITED:

I would like to efficiently create a 1452 x 44 matrix, where:

How can I do this in R? Many thanks in advance!

Upvotes: 1

Views: 127

Answers (1)

Gregor Thomas
Gregor Thomas

Reputation: 145835

After edits, moving my comment to an answer:

x1 = 44
x2 = 1452
m = matrix(c(rep(rep(0:1, c(x1, x2)), x2 / x1 - 1), rep(0, x1)),
           ncol = x2 / x1) 

Essentially, you want a pattern of 44 0s then 1452 1s repeated a bunch. We stick on the last set of 44 0s so it ends on 0 and set the dimensions accordingly.

Upvotes: 2

Related Questions