GEOG 5023 Homework 1

For the first homework assignment I executed four major operations. The first was a computation of the mean using other functions, second was a calcuation of a data set's standard deviation, the thid was writing a forumula to convert a data set from inches to centimeters, and the final was writing a formulat to compute a data set's standard deviation.

Below is the code I used for computing the mean:

# Code to compute mean using sum() and length() functions Enter Data
rizzle <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
# Mean is sum of values over number of entries Compute and check
sum(rizzle)/length(rizzle)
## [1] 19.25
mean(rizzle)
## [1] 19.25

The code I used for computing the standard deviation:

# Code to compute standard deviation Enter Data
rizzle <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
# Step 1: calcualte deviations from mean
rizzle - mean(rizzle)
##  [1] -3.25 -1.25 -5.25  2.75  7.75 -2.25 -0.25 -2.25 -2.25  2.75  0.75
## [12]  2.75
# Step 2: Square the deviations from the mean save the squared deviations
# as a new R object
sqdev <- (rizzle - mean(rizzle))^2
# Step 3: Take the mean of these squared deviations save the results as an
# object.
meansqdev <- mean(sqdev)
# Step 4: Take the square root of the result from the prior step
sqrt(meansqdev)
## [1] 3.394

The unit conversion formula:

# Code for conversion function Enter Data
rizzle <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
# Define function using data
in_to_cm <- function(data) {
    return(data/0.3937)
}
# Execute conversions
in_to_cm(rizzle)
##  [1] 40.64 45.72 35.56 55.88 68.58 43.18 48.26 43.18 43.18 55.88 50.80
## [12] 55.88
(rizzle/0.3937)
##  [1] 40.64 45.72 35.56 55.88 68.58 43.18 48.26 43.18 43.18 55.88 50.80
## [12] 55.88

And the formula to compute standard deviation:

# Code for standard deviation function Enter Data
rizzle <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
# Define function
stdevfun <- function(data) {
    return(sqrt(mean((data - mean(data))^2)))
}
# Report standard deviation
stdevfun(rizzle)
## [1] 3.394

All the values reported comport with those on the assignment.