Skip to content
Back to formatted view

Raw Message

Message-ID: <49A3F733.4040304@erasmusmc.nl>
Date: 2009-02-24T13:33:39Z
From: Dimitris Rizopoulos
Subject: replace zeros in a block diagonal matrix with small random values?
In-Reply-To: <c3cb73d50902240528p34df88dfu2376e32d7f982624@mail.gmail.com>

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