2014-03-25 156 views

回答

2

尝试

nr = 3 # number of rows 
nc = 5 # number of columns 
M = matrix(sample(c(-1, 1), nr * nc, replace = TRUE), nrow = nr) 
print(M) 

    [,1] [,2] [,3] [,4] [,5] 
[1,] -1 -1 -1 1 -1 
[2,] 1 1 1 -1 -1 
[3,] 1 1 1 1 1 
+0

好吧,请与'matrix'和'sample'帮助了解如何?有用。 – Fernando

+0

OK ...当然....... – user2284140