R/rdag.R

rdag <- function (p, nedges) 
{
    stopifnot(nedges >= 0, nedges <= choose(p,2), as.integer(nedges) == nedges)
	M <- matrix(0,p,p)
    M[upper.tri(M)][sample(choose(p,2),nedges)] <- 1
    graph.adjacency(adjmatrix = M)
}

Try the spacejam package in your browser

Any scripts or data that you put into this service are public.

spacejam documentation built on May 2, 2019, 9:13 a.m.