Dear list, 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? Thanks a lot and have a good weekend! Allen>Error in Math.data.frame(CGH) :non-numeric variable in data frame: WM806SignalAWM1716SignalAWM1862SignalAWM1963SignalAWM1968SignalAWM1976SignalAWM3228SignalAWM3457SignalAWM3061SignalAWM3246SignalAWM3282SignalAWM1931SignalAWM1026SignalAWM3670SignalAWM3702SignalAWM3482SignalAWM3311SignalAWM1960SignalAWM1720SignalAWM3215SignalAWM3451SignalAWM3130SignalAWM2029SignalAWM3243NCI.A5SignalAWM1745SignalAWM3526SignalAWM3682SignalAWM3623SignalAWM3450SignalAWM853.2SignalAWM1930SignalAWM3244NCI.BSignalAWM984SignalAWM3619SignalAWM3297SignalAWM451LuSignalAWM3077SignalAWM3381ASignalAWM3627SignalAWM3218SignalAWM3163SignalAWM3259SignalAWM3506SignalAWM3629SignalAWM3456SignalAWM1346SignalAWM1852SignalARCC13NSignalAJAPOV46NSignalAJAPOV75NSignalAS004285NSignalARCC50NSignalAJAPOV54NSignalAJAPOV92NSignalARCC56NSignalAS004288NSignalAS004295NSignalAS004292NSignalAJAPOV73NSignalAJAPOV52NSignalARCC53NSignalAS004289NSignalARCC25NSignalAS004294NSignalAS004275NSignalAJAPOV32NSignalACN37SignalACN16SignalAS004291NSignalACN17SignalARCC129NS
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
On 10-Nov-07 14:25:32, affy snp wrote:> Dear list, > 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?Yes, simply the method you tried: log2(M) where M is the matrix of numeric/complex datavalues. log2() will work just as well on a dataframe whose contents are numerical, as on a simple matrix: M<-data.frame(A=c(1,2,3,4),B=c(2,3,4,5),C=c(3,4,5,6)) log2(M) A B C 1 0.000000 1.000000 1.584963 2 1.000000 1.584963 2.000000 3 1.584963 2.000000 2.321928 4 2.000000 2.321928 2.584963>From the error message you quote below, it looks asthough you have made a mess of reading in, or constructing, the dataframe (the output looks like a series of several variables names, all concatenated together into one long string value). Hoping this helps! Ted.> Thanks a lot and have a good weekend! > > Allen > > >>Error in Math.data.frame(CGH) : > non-numeric variable in data frame: > WM806SignalAWM1716SignalAWM1862SignalAWM1963SignalAWM1968SignalAWM1976Si > gnalAWM3228SignalAWM3457SignalAWM3061SignalAWM3246SignalAWM3282SignalAWM > 1931SignalAWM1026SignalAWM3670SignalAWM3702SignalAWM3482SignalAWM3311Sig > nalAWM1960SignalAWM1720SignalAWM3215SignalAWM3451SignalAWM3130SignalAWM2 > 029SignalAWM3243NCI.A5SignalAWM1745SignalAWM3526SignalAWM3682SignalAWM36 > 23SignalAWM3450SignalAWM853.2SignalAWM1930SignalAWM3244NCI.BSignalAWM984 > SignalAWM3619SignalAWM3297SignalAWM451LuSignalAWM3077SignalAWM3381ASigna > lAWM3627S > ignalAWM3218SignalAWM3163SignalAWM3259SignalAWM3506SignalAWM3629SignalAW > M3456SignalAWM1346SignalAWM1852SignalARCC13NSignalAJAPOV46NSignalAJAPOV7 > 5NSignalAS004285NSignalARCC50NSignalAJAPOV54NSignalAJAPOV92NSignalARCC56 > NSignalAS004288NSignalAS004295NSignalAS004292NSignalAJAPOV73NSignalAJAPO > V52NSignalARCC53NSignalAS004289NSignalARCC25NSignalAS004294NSignalAS0042 > 75NSignalAJAPOV32NSignalACN37SignalACN16SignalAS004291NSignalACN17Signal > ARCC129NS > > ______________________________________________ > 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.-------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 10-Nov-07 Time: 14:43:42 ------------------------------ XFMail ------------------------------
Hi Ted, My matrix looks like:> dim(CGH)[1] 238304 243> CGH[1:30,1:4]WM806SignalA WM1716SignalA WM1862SignalA WM1963SignalA SNP_A-1909444 1.59 1.48 1.78 2.59 SNP_A-2237149 2.24 1.87 1.95 2.04 SNP_A-4303947 2.02 1.70 1.90 2.36 SNP_A-2236359 2.58 2.06 1.87 2.15 SNP_A-2205441 1.87 1.46 1.86 2.40 Even I tried log2(CGH[1:238304,1:243]), it did not work either. Based on the error message, which is:> CGHlog2<-log2(CGH[1:238304,1:243])Error in Math.data.frame(CGH[1:238304, 1:243]) : non-numeric variable in data frame: WM806SignalAWM1716SignalAWM1862SignalAWM1963SignalAWM1968SignalAWM1976SignalAWM3228SignalAWM3457SignalAWM3061SignalAWM3246SignalAWM3282SignalAWM1931SignalAWM1026SignalAWM3670SignalAWM3702SignalAWM3482SignalAWM3311SignalAWM1960SignalAWM1720SignalAWM3215SignalAWM3451SignalAWM3130SignalAWM2029SignalAWM3243NCI.A5SignalAWM1745SignalAWM3526SignalAWM3682SignalAWM3623SignalAWM3450SignalAWM853.2SignalAWM1930SignalAWM3244NCI.BSignalAWM984SignalAWM3619SignalAWM3297SignalAWM451LuSignalAWM3077SignalAWM3381ASignalAWM3627SignalAWM3218SignalAWM3163SignalAWM3259SignalAWM3506SignalAWM3629SignalAWM3456SignalAWM1346SignalAWM1852SignalARCC13NSignalAJAPOV46NSignalAJAPOV75NSignalAS004285NSignalARCC50NSignalAJAPOV54NSignalAJAPOV92NSignalARCC56NSignalAS004288NSignalAS004295NSignalAS004292NSignalAJAPOV73NSignalAJAPOV52NSignalARCC53NSignalAS004289NSignalARCC25NSignalAS004294NSignalAS004275NSignalAJAPOV32NSignalACN37SignalACN16SignalAS004291NSignalACN17SignalARCC129NS it seems that the column names was messed up. How to solve this? Thanks! Allen On Nov 10, 2007 9:43 AM, Ted Harding <Ted.Harding at manchester.ac.uk> wrote:> On 10-Nov-07 14:25:32, affy snp wrote: > > Dear list, > > 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? > > Yes, simply the method you tried: log2(M) where M is > the matrix of numeric/complex datavalues. > > log2() will work just as well on a dataframe whose > contents are numerical, as on a simple matrix: > > M<-data.frame(A=c(1,2,3,4),B=c(2,3,4,5),C=c(3,4,5,6)) > log2(M) > A B C > 1 0.000000 1.000000 1.584963 > 2 1.000000 1.584963 2.000000 > 3 1.584963 2.000000 2.321928 > 4 2.000000 2.321928 2.584963 > > From the error message you quote below, it looks as > though you have made a mess of reading in, or constructing, > the dataframe (the output looks like a series of several > variables names, all concatenated together into one long > string value). > > Hoping this helps! > Ted. > > > Thanks a lot and have a good weekend! > > > > Allen > > > > > >>Error in Math.data.frame(CGH) : > > non-numeric variable in data frame: > > WM806SignalAWM1716SignalAWM1862SignalAWM1963SignalAWM1968SignalAWM1976Si > > gnalAWM3228SignalAWM3457SignalAWM3061SignalAWM3246SignalAWM3282SignalAWM > > 1931SignalAWM1026SignalAWM3670SignalAWM3702SignalAWM3482SignalAWM3311Sig > > nalAWM1960SignalAWM1720SignalAWM3215SignalAWM3451SignalAWM3130SignalAWM2 > > 029SignalAWM3243NCI.A5SignalAWM1745SignalAWM3526SignalAWM3682SignalAWM36 > > 23SignalAWM3450SignalAWM853.2SignalAWM1930SignalAWM3244NCI.BSignalAWM984 > > SignalAWM3619SignalAWM3297SignalAWM451LuSignalAWM3077SignalAWM3381ASigna > > lAWM3627S > > ignalAWM3218SignalAWM3163SignalAWM3259SignalAWM3506SignalAWM3629SignalAW > > M3456SignalAWM1346SignalAWM1852SignalARCC13NSignalAJAPOV46NSignalAJAPOV7 > > 5NSignalAS004285NSignalARCC50NSignalAJAPOV54NSignalAJAPOV92NSignalARCC56 > > NSignalAS004288NSignalAS004295NSignalAS004292NSignalAJAPOV73NSignalAJAPO > > V52NSignalARCC53NSignalAS004289NSignalARCC25NSignalAS004294NSignalAS0042 > > 75NSignalAJAPOV32NSignalACN37SignalACN16SignalAS004291NSignalACN17Signal > > ARCC129NS > > > > ______________________________________________ > > 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. > > -------------------------------------------------------------------- > E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> > Fax-to-email: +44 (0)870 094 0861 > Date: 10-Nov-07 Time: 14:43:42 > ------------------------------ XFMail ------------------------------ >
On Nov 10, 2007 2:49 PM, affy snp <affysnp at gmail.com> wrote:> My matrix looks like: > > > dim(CGH) > [1] 238304 243 > > CGH[1:30,1:4] > WM806SignalA WM1716SignalA WM1862SignalA WM1963SignalA > SNP_A-1909444 1.59 1.48 1.78 2.59 > SNP_A-2237149 2.24 1.87 1.95 2.04 > SNP_A-4303947 2.02 1.70 1.90 2.36 > SNP_A-2236359 2.58 2.06 1.87 2.15 > SNP_A-2205441 1.87 1.46 1.86 2.40 > > Even I tried log2(CGH[1:238304,1:243]), it did not work either. Based > on the error > message, which is: > > > CGHlog2<-log2(CGH[1:238304,1:243]) > Error in Math.data.frame(CGH[1:238304, 1:243]) : > non-numeric variable in data frame: > WM806SignalAWM1716SignalAWM1862SignalAWM1963SignalAWM1968SignalAWM1976SignalAWM3228SignalAWM3457SignalAWM3061SignalAWM3246SignalAWM3282SignalAWM1931SignalAWM1026SignalAWM3670SignalAWM3702SignalAWM3482SignalAWM3311SignalAWM1960SignalAWM1720SignalAWM3215SignalAWM3451SignalAWM3130SignalAWM2029SignalAWM3243NCI.A5SignalAWM1745SignalAWM3526SignalAWM3682SignalAWM3623SignalAWM3450SignalAWM853.2SignalAWM1930SignalAWM3244NCI.BSignalAWM984SignalAWM3619SignalAWM3297SignalAWM451LuSignalAWM3077SignalAWM3381ASignalAWM3627SignalAWM3218SignalAWM3163SignalAWM3259SignalAWM3506SignalAWM3629SignalAWM3456SignalAWM1346SignalAWM1852SignalARCC13NSignalAJAPOV46NSignalAJAPOV75NSignalAS004285NSignalARCC50NSignalAJAPOV54NSignalAJAPOV92NSignalARCC56NSignalAS004288NSignalAS004295NSignalAS004292NSignalAJAPOV73NSignalAJAPOV52NSignalARCC53NSignalAS004289NSignalARCC25NSignalAS004294NSignalAS004275NSignalAJAPOV32NSignalACN37SignalACN16SignalAS004291NSignalACN17SignalARCC129NS > > it seems that the column names was messed up. How to solve this?The first column is not numeric, I guess. That is the problem. Paul
affy snp wrote:> > Hi Ted, > > My matrix looks like: > >> dim(CGH) > [1] 238304 243 >> CGH[1:30,1:4] > WM806SignalA WM1716SignalA WM1862SignalA WM1963SignalA > SNP_A-1909444 1.59 1.48 1.78 2.59 > SNP_A-2237149 2.24 1.87 1.95 2.04 > SNP_A-4303947 2.02 1.70 1.90 2.36 > SNP_A-2236359 2.58 2.06 1.87 2.15 > SNP_A-2205441 1.87 1.46 1.86 2.40 > >As others have commented, the problem seems to be with CGH and not with log2(). str(CGH) should give you more information about what R thinks CGH is. Did you forget to set header=TRUE when reading the data in? Ben Bolker -- View this message in context: http://www.nabble.com/How-to-log-2-transform-a-matrix-tf4782710.html#a13683663 Sent from the R help mailing list archive at Nabble.com.