Kashif Ali
Kashif Ali

Reputation: 197

How to create a customized matrix in R where first few columns are zero and rest are an Identity Matrix?

Suppose we have a matrix A of order k2*k where k=k1+k2 such that k1=k-k2. The characteristic of the matrix A is such that first k1 columns are zero and remaining k2*k2 is an identity matrix. How to create such a customized matrix in R?

NOTE:

For smaller dimensions of k1 and k2, it's easy. But I am looking for an automated command for handling larger dimensions of k1 and k2.

Upvotes: 1

Views: 132

Answers (1)

CL.
CL.

Reputation: 14987

k <- 20
k2 <- 15
k1 <- k - k2

diagonal <- diag(k2)
zeros <- matrix(0, nrow = k2, ncol = k1)

result <- cbind(zeros, diagonal)

Upvotes: 2

Related Questions