[R] Transforming matrix
Emmanuel Paradis
paradis at isem.univ-montp2.fr
Thu Apr 10 16:20:28 CEST 2003
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
More information about the R-help
mailing list