[R] replace zeros in a block diagonal matrix with small random values?
d.rizopoulos at erasmusmc.nl
Tue Feb 24 14:33:39 CET 2009
say 'mat' is your matrix, then you could try something like (untested):
ind <- mat == 0
mat[ind] <- runif(sum(ind))
I hope it helps.
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
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
More information about the R-help