scaleBy {doBy}R Documentation

Groupwise scaling and centering of numeric columns in a dataframe

Description

Groupwise scaling and centering of numeric columns in a dataframe

Usage

scaleBy(formula, data, center = TRUE, scale. = TRUE)

Arguments

formula

A formula. A dot (.) is allowed on both left and right hand side of formula. See 'details' for the meaning of this.

data

A dataframe

center

If TRUE then data is centered to have mean zero

scale.

If TRUE then data is scaled to have variance one

Details

A typical formula is y1+y2~f1+f2 where y1 and y2 are numeric variables and f1 and f2 can be of any type. For each cross-combination of the values of f1 and f2, the variables (y1,y2) are centered/scaled.

It is valid to write .~f1+f2. In this case the variables to be centered/scaled are taken to be all numeric variables in the dataframe except those that a listed on the right hand side of the formula.

It is valid to write y1+y2~.. In this case the stratification is taken to be by all non-numeric variables. If there are no non-numeric variables, then no stratification is made and a 'global' centering/scaling is made.

It is valid to write .~.. In this case the variables to be centered/scaled are taken to be all numeric variables in the dataframe. The stratification is made by all non-numeric variables. If there are no non-numeric variables, then no stratification is made and a 'global' centering/scaling is made.

Value

A dataframe

Note

The workhorse is the funBy function which, alas, is not yet documented.

Author(s)

Søren Højsgaard, sorenh at mail dot dk

See Also

lapplyBy, orderBy, splitBy, summaryBy, transformBy,

Examples


data(dietox)

# "Remove" the effect of time by centering data within each time point.
dietox2 <- scaleBy(Weight~Time, data=dietox, scale=FALSE)

## Not run: 
library(lattice)
xyplot(Weight~Time|Evit+Cu, groups=Pig, data=dietox)
xyplot(Weight~Time|Evit+Cu, groups=Pig, data=dietox2)

## End(Not run)


[Package doBy version 4.5.2 Index]