[R] Scaling on a data.frame

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Tue Jun 4 11:33:04 CEST 2002


On Tue, 4 Jun 2002, Stefan Roepcke wrote:

> hopefully there is an easy way to solve my problem.

I suspect there is, but you do need to state it precisely first.

> All that i think off is lengthy and clumsy.
>
> Given a data.frame d with columns VALUE, FAC1, FAC2, FAC3.
> Let FAC1 be something like experiment number,
> so that there are exactly the same number of rows for each level of FAC1
> in the data.frame.
>
> Now i would like to scale all values according to the center of its
> experiment.
> So i can apply s <- by(d[1], FAC1, scale).

That both centres and scales separately for each level of FAC1: is that
what you want?

> But i don't want to lose the binding to the other factors (FAC2, FAC3).
> Or can i only control it via order preserving - it seems unsave.
>
> Something like that would be nice:
> "by(d[1], FAC1) <- by(d[1], FAC1, scale)"

What precisely do you mean by that?

It can be done by scale: see its argument `center' or the code in
lda.default (MASS).  Something like

grpmeans <- tapply(d[1], FAC1, mean)
d$s <- scale(d[1], grpmeans[d$FAC1], FALSE)

or similarly with scales.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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