Question 1 covered creating a dataset for the heights of a group of males and using R to calculate information about their heights. creating the vector:

males <- c(57.2,66.1,73.1,72.3,69.1,68.9,54.5,65.2,69.3,67,71.2,73,39.5)

1.1 Mean

mean(males)
## [1] 65.10769

1.2 Median

median(males)
## [1] 68.9

1.3 Mode (note that there is not a mode in this dataset, as no two heights are repeated)

stat_mode <- function(males) {
  unique_males <- unique(males)
  unique_males[which.max(tabulate(match(males,unique_males)))]
}
stat_mode(males)
## [1] 57.2

This number is just the first number input. I created a function to find the mode, but there isn’t a repeating value. This function returned the first, and smallest, value.

1.4 Standard Deviation

sd(males)
## [1] 9.566823

1.5 Variance

var(males)
## [1] 91.5241

1.6 Quartiles of the data

quantile(males)
##   0%  25%  50%  75% 100% 
## 39.5 65.2 68.9 71.2 73.1

1.7 Summary of Statistics

summary(males)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   39.50   65.20   68.90   65.11   71.20   73.10

1.8 Histogram

hist(males)

I wanted to create a slightly more exciting histogram here (this is just another option)

hist(males,
     col="skyblue",
     border="black",
     main="Heights of a Group of Males",
     xlab = "Heights",
     ylab = "Frequency")

1.9 Boxplot (whisker plot)

boxplot(males)

1.10 Outliers

outliers <-boxplot.stats(males)$out
outliers
## [1] 54.5 39.5
  1. There is an example of a Pie Chart in question 2, I completed the Pie Chart in R for Question 3. 3.1 Create a Pie Chart
slices <- c(4,5,6,1,4)
lbls <- c("Comedy","Action","Romance", "Drama", "SciFi")
pie(slices, labels = lbls, main="Pie Chart of my Friends' Favorite Movies")

3.2 Create a 3-D Pie Chart

slices2 <- c(140,70,55,5)
lbls2 <- c("Cars","Motorbikes","Vans","Buses")
require(plotrix)
pie3D(slices2,labels = lbls2, main="3D Pie Chart of Traffic")

4.1 Create a Timeseries

data("presidents")
pres_ts <- ts(presidents,start = c(1945,1), frequency = 4)
head(presidents)
## [1] NA 87 82 75 63 50
plot(pres_ts)

4.2 President Kennedy had the highest average approval ratings. Truman had the highest single rating, but that tanked quickly, and ended with some of the lowest ratings in the chart. 4.3 Nixon and Truman had very low ratings, Nixon has the lowest average.

LINKEDINUNIT1 5. A screenshot of the completion of Unit 1 in the Linkedin Learning Course.