[R] Scale function

David Winsemius dwinsemius at comcast.net
Wed Jan 30 05:48:39 CET 2008


pellegrini <pellegrini at ill.fr> wrote in news:479F434D.1030309 at ill.fr:


> There is something that I do not get with scale function.
> 
> Say that I have a vector v <- c(1,2,3,4,5,6),
> 
> scale(v,center=TRUE,scale=TRUE) gives a new vector with 0 as mean
> and 1 as standard deviation.
> 
> but,
> 
> scale(v, center=FALSE,scale=TRUE) gives a new vector with a standard
>  deviation different from 1.
> 
> I would also expect a standard deviation of 1 in that case.
> 
> am I wrong ?

Appears that you are. From the help page:

"If scale is TRUE then scaling is done by dividing the (centered) columns 
of x by their root-mean-square."

"The root-mean-square for a column is obtained by computing the square-
root of the sum-of-squares of the non-missing values in the column 
divided by the number of non-missing values minus one."

> sd(scale(warpbreaks$breaks, scale=TRUE)) #default is center=TRUE
[1] 1
> sd(scale(warpbreaks$breaks, center=FALSE, scale=TRUE))
[1] 0.4212988


-- 
David Winsemius



More information about the R-help mailing list