[R] Coercing Logical array to Numeric array

David Winsemius dwinsemius at comcast.net
Wed Jul 20 15:54:23 CEST 2011


On Jul 20, 2011, at 7:14 AM, Mitra, Sumona wrote:

> Dear all,
>
> Coercing a logical vector to a numeric one is easy. The as.numeric  
> function is used. However what do we use when we have a matrix or an  
> array?

Here's one way:

 > m <-matrix(c("1", "2", "3", "4"),2)
 > m
      [,1] [,2]
[1,] "1"  "3"
[2,] "2"  "4"
 > mode(m) <- "numeric"
 > m
      [,1] [,2]
[1,]    1    3
[2,]    2    4


>
> Sumona
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list