[R] Coercing Logical array to Numeric array

Duncan Murdoch murdoch.duncan at gmail.com
Wed Jul 20 15:52:16 CEST 2011


On 20/07/2011 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?

Usually you don't need to do anything:  if a local is used in 
arithmetic, the values are automatically coerced.  But if you really 
need the conversion, this should work:

newArray <- as.numeric(oldArray)
dim(newArray) <- dim(oldArray)

Duncan Murdoch



More information about the R-help mailing list