Hey, hopefully there is an easy way to solve my problem. 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). 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)" Thanks, Stefan. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Stefan Roepcke <stefan.roepcke at metagen.de> writes:> Hey, > > hopefully there is an easy way to solve my problem. > 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). > 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)"R-1.5.0 has split<- which does this sort of thing. If you have an older version, you should of course upgrade, but the definitions are not very complicated:> get("split<-.data.frame")function (x, f, value) { x[unlist(split(seq(length = nrow(x)), f)), ] <- do.call("rbind", value) x }> get("split<-.default")function (x, f, value) { x[unlist(split(seq(along = x), f))] <- unlist(value) x } The usage is like split(z, g) <- lapply(split(x, g), scale) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._