Ho - R Matrix Commands
Ho - R Matrix Commands
The Matrix
[,1] [,2]
[1,] 2 1
[2,] 3 2
[3,] -2 2
Is Something a Matrix
> is.matrix(A)
[1] TRUE
> is.vector(A)
[1] FALSE
Multiplication by a Scalar
> c <- 3
> c*A
[,1] [,2]
[1,] 6 3
[2,] 9 6
[3,] -6 6
[,1] [,2]
[1,] 1 1
[2,] 4 2
[3,] -2 1
> C <- A + B
> C
[,1] [,2]
[1,] 3 2
[2,] 7 4
[3,] -4 3
> D <- A - B
> D
[,1] [,2]
[1,] 1 0
[2,] -1 0
[3,] 0 1
Matrix Multiplication
> D
[,1] [,2]
[1,] 1 10
[2,] 0 4
[,1] [,2]
[1,] 1 10
Transpose of a Matrix
[,1] [,2]
[1,] 2 1
[2,] 3 2
[3,] -2 2
Common Vectors
Unit Vector
[,1]
[1,] 1
[2,] 1
[3,] 1
Zero Vector
[,1]
[1,] 0
[2,] 0
[3,] 0
Common Matrices
Unit Matrix
[,1] [,2]
[1,] 1 1
[2,] 1 1
[3,] 1 1
Zero Matrix
[,1] [,2]
[1,] 0 0
[2,] 0 0
[3,] 0 0
Diagonal Matrix
[1] 2 2 3
Identity Matrix
Symmetric Matrix
[2,] 1 3 4
[3,] 5 4 -2
Inverse of a Matrix
> A %*% AI
> AI %*% A
[1] -102
Rank of a MatrixM/h4>
[1] 3
[1] 2
[,1] [,2]
[1,] 3 2
[2,] 2 -2
[3,] 4 6
[4,] 3 1
> dim(X)
[1] 4 2
[1] 4
[1] 2
[,1] [,2]
[1,] 2 1
[2,] 3 2
[3,] -2 2
[1] 3 5
[1] 3 5 0
Newsom
Psy 523/623 Structural Equation Modeling, Spring 2018 6
[1] 8
[1] 1.333333
Horizontal Concatenation
> A
[,1] [,2]
[1,] 2 1
[2,] 3 2
[3,] -2 2
[,1] [,2]
[1,] 1 1
[2,] 3 4
[3,] 2 2
[,1] [,2]
[1,] 2 1
[2,] 3 2
[3,] -2 2
[4,] 1 1
[5,] 3 4
[6,] 2 2