0

I tried using the rbern function in R but I realized that the diagonal entries are not all 0's.

Ab2020
  • 21
  • 5
  • 1
    Welcome to SO. Can you show expected output based on a minimal reproducible example? Also show the code you tried. See: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – markus May 28 '20 at 20:36

1 Answers1

0

This would be a possible way:

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
Ahorn
  • 3,686
  • 1
  • 10
  • 17