\(y_{1}\) | \(y_{2}\) | \(y_{3}\) | \(y_{4}\) | ... |
\(y_{j}\) | ... |
\(y_{p}\) |
---|---|---|---|---|---|---|---|
\(y_{11}\) |
\(y_{12}\) |
\(y_{13}\) |
\(y_{14}\) |
|
\(y_{1j}\) |
|
\(y_{1p}\) |
\(y_{21}\) |
\(y_{22}\) |
\(y_{23}\) |
\(y_{24}\) |
|
\(y_{2j}\) |
|
\(y_{2p}\) |
\(y_{31}\) |
\(y_{32}\) |
\(y_{33}\) |
\(y_{34}\) |
|
\(y_{3j}\) |
|
\(y_{3p}\) |
|
|
|
|
|
|
|
|
\(y_{i1}\) |
\(y_{i2}\) |
\(y_{i3}\) |
\(y_{i4}\) |
|
\(y_{ij}\) |
|
\(y_{ip}\) |
|
|
|
|
|
|
|
|
\(y_{n1}\) |
\(y_{n2}\) |
\(y_{n3}\) |
\(y_{n4}\) |
|
\(y_{nj}\) |
|
\(y_{np}\) |
> matrix(c(1,5,10,0,
+ 4,2,3,6,
+ 1,7,4,1),nrow=4,ncol=3)
[,1] [,2] [,3]
[1,] 1 4 1
[2,] 5 2 7
[3,] 10 3 4
[4,] 0 6 1
> M<-matrix(c(1,5,10,
+ 0,4,2,
+ 3,6,1,
+ 7,4,1),nrow=4,ncol=3,byrow=TRUE)
> M
[,1] [,2] [,3]
[1,] 1 5 10
[2,] 0 4 2
[3,] 3 6 1
[4,] 7 4 1
> class(M)
[1] "matrix"
> class(M)
[1] "matrix"
> #dimensions
> dim(M)
[1] 4 3
> nrow(M)
[1] 4
> ncol(M)
[1] 3
> class(M)
[1] "matrix"
> #dimensions
> dim(M)
[1] 4 3
> nrow(M)
[1] 4
> ncol(M)
[1] 3
> colnames(M) <- c('Sp1','Sp2','Sp3')
> rownames(M) <- paste('Site',1:4)
> M
Sp1 Sp2 Sp3
Site 1 1 5 10
Site 2 0 4 2
Site 3 3 6 1
Site 4 7 4 1
If a matrix (\(\textbf{Y}\)) is: \[
\textbf{Y}=[y_{ij}]=
\begin{bmatrix}
7 & 18 & -2 & 6\\
3 & 55 & 1 & 9\\
-4 & 0 & 31 & 7\\
\end{bmatrix}
\] Then the transposed matrix (\(\textbf{Y'}\)) is: \[ \textbf{Y}=[y_{ji}]= \begin{bmatrix} 7 & 3 & -4\\ 18 & 55 & 0\\ -2 & 1 & 31\\ 6 & 9 & 7\\ \end{bmatrix} \] |
|
Conformable matrices - same order
\[ \textbf{A}= \begin{bmatrix} 1&2&3\\ 4&5&6\\ \end{bmatrix} ~,~ \textbf{B}= \begin{bmatrix} 7&8&9\\ 10&11&12\\ \end{bmatrix} \] \[ \begin{array}{rcl} \textbf{A+B} &=& \begin{bmatrix} 1+7 & 2+8 & 3+9\\ 4+10 & 5+11 & 6+12\\ \end{bmatrix}\\ &=&\begin{bmatrix} 8 & 10 & 12\\ 14 & 16 & 18\\ \end{bmatrix} \end{array} \] |
|
Conformable matrices - same order
\[ \textbf{A}= \begin{bmatrix} 1&2&3\\ 4&5&6\\ \end{bmatrix} ~,~ \textbf{B}= \begin{bmatrix} 7&8&9\\ 10&11&12\\ \end{bmatrix} \] \[ \begin{array}{rcl} \textbf{B-A} &=&\textbf{B+(-1)A}\\ &=&\begin{bmatrix} 7+(-1) & 8+(-2) & 9+(-3)\\ 10+(-4) & 11+(-5) & 12+(-6)\\ \end{bmatrix}\\ &=&\begin{bmatrix} 6 & 6 & 6\\ 6 & 6 & 6\\ \end{bmatrix} \end{array} \] |
|
Conformable - nrow(A)=ncol(B)
> A <- matrix(c(1,2,3,4,5,6),nrow=2,ncol=3,byrow=TRUE)
> B <- matrix(c(1,-3,0,5,2,-1),nrow=3,ncol=2)
> A %*% B
[,1] [,2]
[1,] -5 6
[2,] -11 24
Conformable - dim(A)=dim(B)
> A <- matrix(c(1,2,3,4,5,6),nrow=2,ncol=3,byrow=TRUE)
> B <- matrix(c(7,8,9,10,11,12),nrow=2,ncol=3, byrow=TRUE)
> A * B
[,1] [,2] [,3]
[1,] 7 16 27
[2,] 40 55 72
> A <- matrix(c(1,2,3,4,5,6),nrow=2,ncol=3,byrow=TRUE)
> B <- matrix(c(2,3), nrow=2, ncol=1, byrow=TRUE)
> sweep(A,1,B,'*')
[,1] [,2] [,3]
[1,] 2 4 6
[2,] 12 15 18
> A <- matrix(c(1,2,3,4,5,6),nrow=2,ncol=3,byrow=TRUE)
> B <- matrix(c(2,3,4), nrow=1, ncol=3, byrow=FALSE)
> sweep(A,2,B,'+')
[,1] [,2] [,3]
[1,] 3 5 7
[2,] 6 8 10