[R] Odp: logical to numeric matrix changing dimensions
Petr PIKAL
petr.pikal at precheza.cz
Wed Jul 14 09:56:46 CEST 2010
Hi
r-help-bounces at r-project.org napsal dne 14.07.2010 07:54:51:
> example:
> > y=(rbind(c(TRUE,TRUE,TRUE),c(FALSE,FALSE,FALSE)))
> > y
> [,1] [,2] [,3]
> [1,] TRUE TRUE TRUE
> [2,] FALSE FALSE FALSE
> > as.numeric(y)
> [1] 1 0 1 0 1 0
>
> I am trying to make some important matrixes become nuemric (1 or 0) but
they
> change their dimensions.. anyone know how to easily fix it??
Matrix is only vector with dimensions, and function as.numeric creates a
vector changed to numeric so it strips dimensions.For your purpose I would
use
y+0 or y*1
or maybe you can use logical matrix directly in your computations.
Regards
Petr
>
>
> Tks in advance.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list