lundi 17 avril 2023

Making a random presence/absence matrix in R with row and column constraints

I am trying to create a randomized matrix in R. It needs to be a presence/absence matrix, such that all values in the matrix are either 0 or 1. But I also need to specify row and column totals, for example, a 5x5 table where the row totals are: r1 = 4, r2, = 2, r3 = 3, r4 = 5, r5 = 3 and the column totals are: c1 = 5, c2 = 1, c3 = 5, c4 = 2, c5 = 4.

I was hoping to use r2dtable(), but I don't think you can force this function to use only 0's and 1's.

Are there any ideas?

Thanks!

I've tried using r2dtable() but end up with values higher than 1.




Aucun commentaire:

Enregistrer un commentaire