Homework 1
# Homework 1: Create a Standard Deviation Function Done by: Andy Staffer
######################################################## Create function
RMS_StDev <- function(inData) {
# Calculate deviations from mean
deviations <- rain - mean(inData)
# square the deivations from the mean
sqDev <- (deviations)^2
# calculate mean of square deviations
avgSqDev <- mean(sqDev)
# calculate square root of squared means
rms_stdev <- sqrt(avgSqDev)
# return result
return(rms_stdev)
}
# get answer Boulder Rainfall, 2000 to 2011
rain <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
myRMS_StDev <- RMS_StDev(rain)
paste("the RMS Standard Deviation of the Rainfall in Boulder from 2000 to 2011 is",
myRMS_StDev, "inches.")
## [1] "the RMS Standard Deviation of the Rainfall in Boulder from 2000 to 2011 is 3.39423530906938 inches."