> #覯″ > x <- c(1,2,3) > y <- c(4,5,6) > z <- c(7,8,9) > #覦覯1: cbind()襦 企 覿願鍵 > cbind(x,y,z) x y z [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 > #覦覯2: rbind()襦 朱 覿願鍵 > rbind(x,y,z) [,1] [,2] [,3] x 1 2 3 y 4 5 6 z 7 8 9
> #覦覯3: matrix 蠍 > c(x,y,z) [1] 1 2 3 4 5 6 7 8 9 > matrix(c(x,y,z), nrow = 3) [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 > matrix(c(x,y,z), ncol = 3) [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 > matrix(c(x,y,z), nrow = 3) [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 > matrix(c(x,y,z), nrow = 3, byrow = T) # 一豈 [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 [3,] 7 8 9 > matrix(c(x,y,z), byrow=T) # 一豈 [,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 > matrix(c(x,y,z), ncol = 3, byrow = T) #2覯讌 語 , 伎 蠍磯ゼ 蟆一. 3覯讌 語 一 讌. [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 [3,] 7 8 9 > > matrix(c(x,y,z), ncol = 2, byrow=T) [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6 [4,] 7 8 [5,] 9 1 > matrix(c(x,y,z), ncol = 1, byrow = T) #企押 [,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 > matrix(c(x,y,z), nrow = 1, byrow = T) #覯″ [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 1 2 3 4 5 6 7 8 9 >
> dim(c(x,y,z)) <- c(2,2) 危 dim(c(x, y, z)) <- c(2, 2) : dims [product 4] do not match the length of object [9] > dim(c(x,y,z)) <- c(3,3) 危 dim(c(x, y, z)) <- c(3, 3) : "c<-"襯 蟆企殊螳 給 > data <- c(x,y,z) > dim(data) <- c(3,3) > data [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 >
> x <- c(1,3,5,0) > diag(x) #螳 [,1] [,2] [,3] [,4] [1,] 1 0 0 0 [2,] 0 3 0 0 [3,] 0 0 5 0 [4,] 0 0 0 0 > diag(1:5) [,1] [,2] [,3] [,4] [,5] [1,] 1 0 0 0 0 [2,] 0 2 0 0 0 [3,] 0 0 3 0 0 [4,] 0 0 0 4 0 [5,] 0 0 0 0 5 > diag(rep(1,3)) # [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 >
> m <- matrix(1:9, nrow = 3, byrow = T) > m [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 [3,] 7 8 9 > upper.tri(m) [,1] [,2] [,3] [1,] FALSE TRUE TRUE [2,] FALSE FALSE TRUE [3,] FALSE FALSE FALSE > lower.tri(m) [,1] [,2] [,3] [1,] FALSE FALSE FALSE [2,] TRUE FALSE FALSE [3,] TRUE TRUE FALSE > upper.tri(m) * m [,1] [,2] [,3] [1,] 0 2 3 [2,] 0 0 6 [3,] 0 0 0 > lower.tri(m) * m [,1] [,2] [,3] [1,] 0 0 0 [2,] 4 0 0 [3,] 7 8 0 > upper.tri(m, diag = T) * m #手, 螻煙 螳 豺 朱Μ 螻煙企. [,1] [,2] [,3] [1,] 1 2 3 [2,] 0 5 6 [3,] 0 0 9 > lower.tri(m, diag = T) * m #手 [,1] [,2] [,3] [1,] 1 0 0 [2,] 4 5 0 [3,] 7 8 9 >