Nice solution :)
Another one:
m <- matrix(c(T,T,F,T),nr=2)
m
matrix(as.integer(m), dim(m))
-
--
http://djhurio.wordpress.com/
http://twitter.com/djhurio
http://www.linkedin.com/in/martinsliberts
http://www.csb.gov.lv/
--
View this message in context:
http://r.789695.n4.nabble.com/Chang
Thanks for everyone's suggestionsI didn't realise it was so
straightforward- thanks for teaching me new tricks!
Emma
--
View this message in context:
http://r.789695.n4.nabble.com/Changing-a-logical-matrix-into-a-numeric-matrix-tp3206797p3206844.html
Sent from the R help mailing list archiv
Hi,
Try this,
mode(m) <- "integer"
HTH,
baptiste
On 10 January 2011 10:17, emj83 wrote:
>
> 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
>
>
On 10-Jan-11 09:17:26, emj83 wrote:
> 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,]10 0
>
Hi Emma,
The easiest way I know uses a bit of a trick. If your matrix is named 'X'
Then: X + 0 will convert it to numeric data.
HTH,
Josh
On Jan 10, 2011, at 1:17, emj83 wrote:
>
> Hi,
>
> I would like to turn my TRUE/FALSE matrix into a 1/0 matrix (i.e. True=1 and
> False=0)
>
> [,1
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,]10
[2,]11
-Oprindelig meddelelse-
Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På
vegne af emj83
Sendt: 10. janua
6 matches
Mail list logo