i want to find "if matrix b is nonsingular matrix, find inverse of b else if then find generalized inverse of b"
so i made this statement . but it didn't work.
a<-c(1:9)
a
b<-matrix(a,3,3)
b
library(MASS)
ifelse(ncol(b)==nrow(b),(ifelse(det(b)==0,ginv(b),solve(b)),ginv(b))
then i modified the statement like this
a<-c(1:9)
a
b<-matrix(a,3,3)
b
library(MASS)
d<-ifelse(det(b)==0,ginv(b),solve(b))
e<-ginv(b)
ifelse(ncol(b)==nrow(b),d,e)
but the answer is just row=1 col=1 value of the generalize invers of b.
Please help me....