I have a matrix generating function that produces lower-triangle of 1
s and upper-triangle of 0s
.
I was wondering if it might be possible to add some adjustable random noise (from some distribution that gives random 0
and 1
) to the outputted matrix such that the random 0
s randomly replace some of the bottom 1
s, and random 1
s randomly replace some of the top 0
s?
lower_mat <- function(r, c) {
m <- matrix(0, nrow=r,ncol=c)
m[lower.tri(m)] <- 1
m
}
lower_mat(5,4)
# [,1] [,2] [,3] [,4]
# [1,] 0 0 0 0
# [2,] 1 0 0 0
# [3,] 1 1 0 0
# [4,] 1 1 1 0
# [5,] 1 1 1 1
Aucun commentaire:
Enregistrer un commentaire