Skip to content
Back to formatted view

Raw Message

Message-ID: <4.2.0.58.20030410161218.00b1a128@162.38.183.200>
Date: 2003-04-10T14:20:28Z
From: Emmanuel Paradis
Subject: Transforming matrix
In-Reply-To: <20030410135646.68565.qmail@web20308.mail.yahoo.com>

At 15:56 10/04/2003 +0200, vous avez ?crit:

>hi everybody,
>anyone knows how we can transform a binary matrix with TRUE and FALSE to 0 
>and 1 without looping?
>Thx

I guess you mean:

  TRUE ==> 1
FALSE ==> 0

as this is the rule when logicals are converted into numerics. Then, if M 
is your matrix, you can do:

mode(M) <- "numeric"

If you actually want:

  TRUE ==> 0
FALSE ==> 1

then:

M <- !M
mode(M) <- "numeric"

should do it.

HTH

EP



>---------------------------------
>
>
>         [[alternate HTML version deleted]]
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help