Home > Mobile >  Matrix multiplication with vector based on another matrix in R
Matrix multiplication with vector based on another matrix in R

Time:03-16

I need to multiply one matrix with one conditional vector, to get a vector of solutions, based on another matrix.

# Matrix A
lsA <- c(1,1,0,1,1,2,1,0,1,2,1,1,0,0,1,1,0,0,0,1)
A <- matrix(lsA,4,5, byrow = T)

# Matrix B
ls <- c("10","11","01","10","01","00","11","01","11","10","10","11","00","12","12","02","22","02","03","11")
B <- matrix(ls,4,5, byrow = T)

a1 <- c(0.128, 0.130, 0.280, 0.500, 0.650)
a2 <- c(0.055, 0.120, 0.250, 0.430, 0.600)

M1 = A%*           
  • Related