Generating random sparse matrix
问题 I am dealing with large matrices - on the order of 10^8 columns and 10^3-10^4 rows. Since these matrices are only ones and zeros (over 99% zeros), I think the sparse construction in the Matrix package is appropriate. However, I don't see a way to generate a random matrix like in the example below. Note that non-zero entries are defined by the column probabilities col_prob . set.seed(1) #For reproducibility ncols <- 20 nrows <- 10 col_prob <- runif(ncols,0.1,0.2) rmat <- matrix(rbinom(nrows