Can someone please help? Cannot solve this matrix using R. The code is reproducible.
(a <- matrix(c(1, 0, 1, 0, 10, 1, 0, 0, 1, 20, 0, 1, 1, 0, 5, 0, 1, 0, 1, 10), nrow = 5))
(b <- matrix(c(20, 15, 10, 25, 475), nrow = 5))
solve(a) %*% b
Can someone please help? Cannot solve this matrix using R. The code is reproducible.
(a <- matrix(c(1, 0, 1, 0, 10, 1, 0, 0, 1, 20, 0, 1, 1, 0, 5, 0, 1, 0, 1, 10), nrow = 5))
(b <- matrix(c(20, 15, 10, 25, 475), nrow = 5))
solve(a) %*% b
 
    
    You have a non-square matrix. Since it has more rows than columns, you can use OLS:
> lm.fit(a, b)$coefficients
x1 x2 x3 x4 
 5 15  5 10 
Alternatively you can use a generalized inverse, e.g. from MASS:
> MASS::ginv(a) %*% b
     [,1]
[1,]    5
[2,]   15
[3,]    5
[4,]   10
