Standardization of a data frame based on another data frame
Standardization of a data frame based on another data frame
Centers and scales a data frame. See Details.
stand(tab, ref.tab=NULL, center=NULL, scale=NULL)
Arguments
tab: data frame to scale.
ref.tab: optional reference data frame, from which centering and scaling parameters are obtained (see Details).
center: optional vector of centering parameters (one per column of tab). See Details.
scale: optional vector of scaling parameters (one per column of tab). See Details.
Details
If ref.tab is not NULL, centering and scaling parameters are looked for into this data frame. If it has a "scaled:center" attribute, this one is used to center tab. Otherwise means of ref.tab's columns are used. The same happens for scaling parameters (with the "scaled:scale" attribute and standard deviations).
If ref.tab is NULL, values of center and scale are used to standardize tab.
If ref.tab and center are NULL, means of tab's columns are used for centering. If ref.tab and scale are NULL, standard deviations of tab's columns are used for scaling.
data(iris)set.seed(1131)iris.samp <- iris[sample(1:150,10),1:4]# Centering parameters of the complete datasetattr(scale(iris[,1:4]),"scaled:center")# Centering parameters of the reduced datasetattr(scale(iris.samp),"scaled:center")# Standardization based on the reduced dataset onlyattr(stand(iris.samp),"scaled:center")# Standardization based on the complete datasetattr(stand(iris.samp,iris[,1:4]),"scaled:center")