Rick DeShon
2009-Feb-24 13:28 UTC
[R] replace zeros in a block diagonal matrix with small random values?
Hi All. Imagine you have a large block diagonal matrix. I'd like to replace the zeros in this matrix with small random (runif) numbers. Any ideas for a simple and efficient way to do this? Best regards, Rick DeShon
Dimitris Rizopoulos
2009-Feb-24 13:33 UTC
[R] replace zeros in a block diagonal matrix with small random values?
say 'mat' is your matrix, then you could try something like (untested): ind <- mat == 0 mat[ind] <- runif(sum(ind)) I hope it helps. Best, Dimitris Rick DeShon wrote:> Hi All. > > Imagine you have a large block diagonal matrix. I'd like to replace > the zeros in this matrix with small random (runif) numbers. Any ideas > for a simple and efficient way to do this? > > Best regards, > > Rick DeShon > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014