Search code examples
rmatrixsocial-networkingadjacency-matrixsna

Is there a method for generating a rectangular matrix?


I'm generating networks using the rgnm function from the sna package. E.g.

int_mat <- rgnm (1,10,33)

Is there a method that I can use to produce a non-square matrix (e.g. 10 x 11 matrix) using this or another function?

Thanks!


Solution

  • This seems to do what you want.

    n_rows <- 10; n_cols <- 11; n_1s <- 33
    elements <- rep(0, n_rows* n_cols)
    elements[sample(1:length(elements), 33)] <- 1
    int_mat <- matrix(elements, nrow=n_rows, ncol=n_cols)