Hi, I am new to R an dI need some help I have a matrix of real values 100*300 and I would like to calculate the mean for each column , then for each entry in a column i need to subtract the mean so I will have a matrix where the columns have zero mean. any one know how to do that . Thanks -- View this message in context: http://www.nabble.com/subtract-the-mean-from-each-column-tp16610489p16610489.html Sent from the R help mailing list archive at Nabble.com.
On 4/10/2008 1:03 PM, kayj wrote:> Hi, > > I am new to R an dI need some help > I have a matrix of real values 100*300 and I would like to calculate the > mean for each column , then for each entry in a column i need to subtract > the mean so I will have a matrix where the columns have zero mean. any one > know how to do that . Thanksmymat <- matrix(runif(10*4), ncol=4) colMeans(mymat) [1] 0.4711083 0.4825977 0.4757448 0.3037873 newmat <- apply(mymat, 2, scale, scale=FALSE, center=TRUE) colMeans(newmat) [1] 1.110223e-17 -2.220446e-17 -1.110223e-17 1.110223e-17 ?scale -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
Or just: scale(mymat, scale = FALSE) On Thu, Apr 10, 2008 at 2:03 PM, kayj <kjaja27@yahoo.com> wrote:> > Hi, > > I am new to R an dI need some help > I have a matrix of real values 100*300 and I would like to calculate the > mean for each column , then for each entry in a column i need to subtract > the mean so I will have a matrix where the columns have zero mean. any one > know how to do that . Thanks > -- > View this message in context: > http://www.nabble.com/subtract-the-mean-from-each-column-tp16610489p16610489.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]