r – Why is sd() and var() returning different values?
I have a question regarding computing standard deviation and variance in R. Lets say that I ask R to provide me with the standard deviation and variance for my variable “x”:
x<-rnorm(200, mean = 1300171, sd = 41165.34)
df<-data.frame(x)
var(df$x)
sd(df$x)
If I take the standard deviation and square it through R, I receive a value that corresponds to the original variance value that R previously provided:
var(df$x) #original variance value
sd(df$x) * sd(df$x) # Variance value congruent with original value
sd(df$x)^2 #Variance value congruent with original value
However, if I take the standard deviation that R provides me and multiply it by itself or square it, I receive a different variance value than what R’s computations provide me. I’ve used an example below to try and reproduce this:
#Example
#var(df$x) = 1610178408
#sd(df$x)= 40127.03
#40127.03^2 = 1610178537
#40127.03 * 40127.03 = 1610178537
Would anyone know why there is a discrepancy between what R provides through its functions and what is provided by manually solving for variance?
Read more here: Source link
