[R] transforming a matrix of logical to 0 and 1 while keeping the dim of matrix

Julian TszKin Chan cjulian at bu.edu
Wed Jul 20 17:16:18 CEST 2011

Hi all,

Suppose I have a matrix of logical value:


I would like to change the value of FALSE to 0 and TRUE to 1. An
obvious way to do it is :

However this method doesn't keep the dim of x. I also need to copy the
dim information to y too.

Is this a correct way to do it in R? Is there any single step function
which can do the something? Thanks

TszKin Julian

More information about the R-help mailing list