简体   繁体   中英

Multiply matrices with Loop in R

I have a matrix "eps" with 2 rows and n columns. I also have a matrix B with 2 rows and 2 columns. I want to multiply the inverse of B with each column of "eps" to acquire n new matrices dimension 2x1. Then I transpose those n new matrices for dimension 1x2 and fill them in matrix U which has 2 columns and n rows.

But my code below is wrong with the message "Error: unexpected symbol in "for i"" from R. Could you please help me? Thanks a lot!

for i in 1:nrow(U){U[i,] <- t(solve(B)%*%eps[,i])}

U <- t(solve(B, eps)) and done!

Regarding the error: for (i in 1:nrow(U)) please read ?Control .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM