1. 程式人生 > >R語言學習-建立空矩陣

R語言學習-建立空矩陣

方法一:
x <- rep(0,15)
dim(x) <- c(3,5)
x
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    0    0    0    0    0
[3,]    0    0    0    0    0

方法二:
x <- matrix(0,3,5)
x
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    0    0    0    0    0
[3,]    0    0    0    0    0