1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| x1=c(171,175,159,155,152,158,154,164,168,166,159,164) > x1 [1] 171 175 159 155 152 158 154 164 168 166 159 164 > x2=c(57,64,41,38,35,44,41,51,57,49,47,46);x2 [1] 57 64 41 38 35 44 41 51 57 49 47 46 > rbind(x1,x2) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] x1 171 175 159 155 152 158 154 164 168 166 159 164 x2 57 64 41 38 35 44 41 51 57 49 47 46 > cbind(x1,x2) x1 x2 [1,] 171 57 [2,] 175 64 [3,] 159 41 [4,] 155 38 [5,] 152 35 [6,] 158 44 [7,] 154 41 [8,] 164 51 [9,] 168 57 [10,] 166 49 [11,] 159 47 [12,] 164 46
> matrix(x1,nrow=3,ncol=4) [,1] [,2] [,3] [,4] [1,] 171 155 154 166 [2,] 175 152 164 159 [3,] 159 158 168 164
> matrix(x1,nrow=4,ncol=3) [,1] [,2] [,3] [1,] 171 152 168 [2,] 175 158 166 [3,] 159 154 159 [4,] 155 164 164
> A=B=matrix(1:12,nrow=3,ncol=4) > A+B [,1] [,2] [,3] [,4] [1,] 2 8 14 20 [2,] 4 10 16 22 [3,] 6 12 18 24 > A-B [,1] [,2] [,3] [,4] [1,] 0 0 0 0 [2,] 0 0 0 0 [3,] 0 0 0 0
> A=matrix(1:9,nrow=3,ncol=3) > B=matrix(1:9,nrow=3,ncol=3) > A*B [,1] [,2] [,3] [1,] 1 16 49 [2,] 4 25 64 [3,] 9 36 81 > A%*%B [,1] [,2] [,3] [1,] 30 66 102 [2,] 36 81 126 [3,] 42 96 150
> A=matrix(1:16,nrow=4,ncol=4) > diag(A) [1] 1 6 11 16 > diag(diag(A)) [,1] [,2] [,3] [,4] [1,] 1 0 0 0 [2,] 0 6 0 0 [3,] 0 0 11 0 [4,] 0 0 0 16
> A=matrix(rnorm(16),4,4) > solve(A) [,1] [,2] [,3] [,4] [1,] -0.2144625 0.9291739 0.41134588 -0.4129970 [2,] -0.2990380 0.5107384 -0.03081756 0.6477244 [3,] -0.1700996 1.4089089 -0.49639658 0.4082339 [4,] -0.4334604 -0.3543499 -0.30915934 -0.5515849 > A=diag(4)+1 > A.e=eigen(A,symmetric=T) > A.e eigen() decomposition $values [1] 5 1 1 1
$vectors [,1] [,2] [,3] [,4] [1,] -0.5 0.8660254 0.0000000 0.0000000 [2,] -0.5 -0.2886751 -0.5773503 -0.5773503 [3,] -0.5 -0.2886751 -0.2113249 0.7886751 [4,] -0.5 -0.2886751 0.7886751 -0.2113249
> A=matrix(1:12,3,4) > dim(A) [1] 3 4 > nrow(A) [1] 3 > ncol(A) [1] 4 > rowSums(A) [1] 22 26 30 > rowMeans(A) [1] 5.5 6.5 7.5 > colSums(A) [1] 6 15 24 33 > colMeans(A) [1] 2 5 8 11
|