0

我尝试在 R 中使用 rbern 函数,但我意识到对角线条目并非全为 0。

4

1 回答 1

0

这将是一种可能的方式:

m <- 10
n <- 10
mat <- matrix(sample(0:1,m*n, replace=TRUE),m,n)
diag(mat) <- 0

#> mat
#      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
# [1,]    0    1    1    0    1    0    0    0    1     0
# [2,]    1    0    1    1    0    0    1    0    0     1
# [3,]    0    0    0    1    0    1    0    0    1     0
# [4,]    0    1    0    0    0    0    0    0    1     0
# [5,]    0    1    1    1    0    0    1    1    0     0
# [6,]    1    0    1    0    1    0    0    0    1     0
# [7,]    1    1    1    0    0    0    0    0    1     1
# [8,]    1    0    1    1    1    1    1    0    1     1
# [9,]    1    1    1    1    1    1    0    0    0     1
#[10,]    1    0    1    0    1    0    0    0    1     0
于 2020-05-28T20:40:58.440 回答