Message-ID: <9F0721FDD4F12D4B95AD894274F388EC020C63EC3C0A@DJFEXMBX01.djf.agrsci.dk>
Date: 2011-01-10T09:30:13Z
From: Søren Højsgaard
Subject: Changing a logical matrix into a numeric matrix
In-Reply-To: <1294651046014-3206797.post@n4.nabble.com>
Just multiply by 1:
> m <- matrix(c(T,T,F,T),nr=2)
> m
[,1] [,2]
[1,] TRUE FALSE
[2,] TRUE TRUE
> m*1
[,1] [,2]
[1,] 1 0
[2,] 1 1
-----Oprindelig meddelelse-----
Fra: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] P? vegne af emj83
Sendt: 10. januar 2011 10:17
Til: r-help at r-project.org
Emne: [R] Changing a logical matrix into a numeric matrix
Hi,
I would like to turn my TRUE/FALSE matrix into a 1/0 matrix (i.e. True=1 and
False=0)
[,1] [,2] [,3]
[1,] TRUE FALSE FALSE
[2,] TRUE TRUE FALSE
[3,] TRUE TRUE TRUE
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 1 1 0
[3,] 1 1 1
Is there a quick way of doing this without a loop?
Thanks Emma
--
View this message in context: http://r.789695.n4.nabble.com/Changing-a-logical-matrix-into-a-numeric-matrix-tp3206797p3206797.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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.