[R] standardising a data matrix

Douglas Bates bates at stat.wisc.edu
Fri Mar 2 15:31:29 CET 2001


Paulo Justiniano Ribeiro Jr <p.ribeiro at lancaster.ac.uk> writes:

> What about apply:

> apply(onorm, 2, function(x){(x - mean(x))/sqrt(var(x))})

I think if the data were read with read.table they would be in the
form of a data frame and you would need to use lapply, not apply.  It
would look like

  lapply(onorm, function(x){(x - mean(x))/sqrt(var(x))})

I have a vague recollection of a function in the base library that
does centering and scaling but I can't remember what it is called.  It
is certainly easy enough to create an anonymous function as you did
although that function will encounter problems with missing data.


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list