Skip to content
Prev 76410 / 398502 Next

reexpand a matrix after subsetting

1) Do you really need to turn rows 3, 6, 9 of mat into NA ? I would
suggest the use of usediff() to remove them after complete.cases

2) The trick is to create a matrix of the same dimension as 'mat' but
initialised with NAs followed by replacing the required rows.

Example :

   w <- which( complete.cases(mat) )
   w <- setdiff( w, c(3,6,9) )
 
   out <- matrix( NA, nr=nrow(mat), nc=ncol(mat) )
   out[ w, ] <- 2 * mat[ w, ]

Regards, Adai
On Mon, 2005-08-29 at 18:11 +0200, Ido M. Tamir wrote: