[R] How to log-2 transform a matrix

Paul Smith phhs80 at gmail.com
Sat Nov 10 15:30:13 CET 2007


On Nov 10, 2007 2:25 PM, affy snp <affysnp at gmail.com> wrote:
> I am wondering how to log-2 based transform a matrix with numeric values?
> I tried > CGHlog2<-log2(CGH) but got an error. Then I found for log2(x) in R,
> the x has to be a numeric or complex vector. Any method for a matrix?

One can use log2 with matrices:

> m <- matrix(1:9,3)
> m
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
> log2(m)
         [,1]     [,2]     [,3]
[1,] 0.000000 2.000000 2.807355
[2,] 1.000000 2.321928 3.000000
[3,] 1.584963 2.584963 3.169925
>

Paul



More information about the R-help mailing list