How to calculate / normalize the average and unit variance

What is "Zero Mean and Unit Variance" and how to calculate / normalize it for a single column file in R? I also want to divide the normalized values ​​into two classes:

  • normalized value of at least 0.5 standard deviation (SD) above average
  • normalized value of at least 0.5 standard deviation (SD) below average

thank

+4
source share
1 answer

" " , 0 ( ) 1. R scale. :

# create vector
set.seed(1234)
temp <- rnorm(20, 3, 7)

# take a look
> mean(temp)
[1] 1.245352
> sd(temp)
[1] 7.096653

# scale vector
tempScaled <- c(scale(temp))

# take a look
> mean(tempScaled)
[1] 1.112391e-17
> sd(tempScaled)
[1] 1

# find values below 0.5 standard deviation in scaled vector
tempScaled[tempScaled < -0.5]
# find values above 0.5 standard deviation in scaled vector
tempScaled[tempScaled > 0.5]

:

tempScaled2 <- (temp - mean(temp)) / sd(temp) 

> all.equal(tempScaled, tempScaled2)
[1] TRUE
+4

All Articles