r语言矩阵运算
R offers extensive matrix handling capabilities. In addition to the basic operations discussed earlier, there are several advanced matrix functions that will ease your statistical programming efforts. This tutorial will illustrate such functions with examples.
R提供了广泛的矩阵处理功能。 除了前面讨论的基本操作外,还有一些高级矩阵函数可简化统计编程工作。 本教程将通过示例说明此类功能。
R中的矩阵转置 (Transpose of Matrix in R)
The transpose of a matrix A is simply another matrix with the rows and columns interchanged. This can be calculated using t(A)
in R.
矩阵A的转置只是行和列互换的另一个矩阵。 可以使用R中的t(A)
来计算。
#Define a rectangular matrix
> rectmatrix<-matrix(c(2,3,4,5,6,7),nrow=2,ncol=3)
> rectmatrix
[,1] [,2] [,3]
[1,] 2 4 6
[2,] 3 5 7
> rectmatrix
[,1] [,2] [,3]
[1,] 2 4 6
[2,] 3 5 7
> t(rectmatrix)
[,1] [,2]
[1,] 2 3
[2,] 4 5
[3,] 6 7

R中矩阵的对角线 (Diagonals of a Matrix in R)
R has the diag()
function to create a diagonal matrix from a vector. The sam