[Rd] scale(x, center=FALSE) (PR#14219)

mrizzo at bgsu.edu mrizzo at bgsu.edu
Mon Feb 22 04:30:11 CET 2010

Full_Name: Maria Rizzo
Version: 2.10.1 (2009-12-14) 
OS: Windows XP SP3
Submission from: (NULL) (

platform       i386-pc-mingw32              
arch           i386                         
os             mingw32                      
system         i386, mingw32                
major          2                            
minor          10.1                         
year           2009                         
month          12                           
day            14                           
svn rev        50720                        
language       R                            
version.string R version 2.10.1 (2009-12-14)

scale returns incorrect values when center=FALSE and scale=TRUE.

When center=FALSE, scale=TRUE, the "scale" used is not the square root of sample
variance, the "scale" attribute is equal to sqrt(sum(x^2)/(n-1)).


x <- runif(10)
n <- length(x)

scaled <- scale(x, center=FALSE, scale=TRUE)
s.bad <- attr(scaled, "scale")
s.bad  #wrong
sd(x)  #correct

#compute the sd as if data has already been centered
#that is, compute the variance as sum(x^2)/(n-1)


More information about the R-devel mailing list