Search code examples
rscale

Why does scale center=F change the mean?


As the title says, how does the following come about:

set.seed(1)  # for reproducibility
x <- rnorm(30, 10, 2)

mean(x)
# [1] 10.16492
mean(scale(x, center=FALSE))
# [1] 0.9678482

Solution

  • ?scale explains all: "scaling is done by dividing the (centered) columns of x by their standard deviations if center is TRUE, and the root mean square otherwise."

    We can show that scaling by the RMS is what actually happened:

    rms = sqrt(sum(x^2)/(length(x)-1))
    mean(x)/rms
    # [1] 0.9678482