Write a function to compute the standard deviation, use the four steps outlined above. Do not use the internal sd() function to check your work because it uses \( \sqrt{\frac{1}{N} \sum_{i=1}^N (x_i - \overline{x})^2} \), note the N-1 in the denominator. Your function is correct if you find a standard deviation of around 3.39.
Define my own function (standard_deviation) for computing the standard deviation:
standard_deviation <- function(inputData) {
deviation <- inputData - mean(inputData)
squareDeviation <- deviation^2
meanSquareDeviation <- mean(squareDeviation)
return(sqrt(meanSquareDeviation))
}
Import the rain data:
## 'rain' contains actual rainfall data for Boulder, CO (2000-2011)
rain <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
Calculate the standard deviation of the rain data:
sdRain <- standard_deviation(rain)
sdRain
## [1] 3.394
Created by: Li Xu Created on: 1/25/2013 Last updated: 1/25/2013