I need to compute a matrix base on a logical expression.
I have a matrix called A and a matrix called B:
A=matrix(c(1,1,1,1),nrow=2,ncol=2)
B=matrix(c(2,2,2,2),nrow=2,ncol=2)
Based on whether a variable called lambda is equal to one, I want to compute a matrix C, which is equal to A. On the other hand, if lambda is equal to zero, the matrix C should be equal to the matrix B. It should look something like this, but it doesn't seem to work:
C=ifelse(lambda==1,A,B)
Thanks.