Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我想使用两个矩阵来执行基本的数学运算。
作为我的输入,我有两个 3x3 矩阵。我想将 matrixA 中的每个整数除以 matrixB 中的每个整数,输出是它们产品的一个 3x3 矩阵。
可以为我做到这一点的 R 函数是什么。
提前致谢!
听起来您想逐个元素地划分元素。在这种情况下,您可以简单地使用/运算符。
/
### Create two matrices matA <- matrix(1:9, nrow = 3) matB <- matA ### Divide element by element matB / matA ### As Frank pointed out, division by 0 goes to Inf matA[1, 1] <- 0 matB / matA