Load Table 6 from Section 2.3 into R. Recall, Table 6 from Section 3.1 is Table 1 from Section 2.1
Table6 <- read.csv("https://sullystats.github.io/Statistics6e/Data/Chapter2/Table1.csv")
head(Table6,n=5)
## Location
## 1 Back
## 2 Wrist
## 3 Elbow
## 4 Back
## 5 Hip
R does not have a built-in function for calculating the mode of a vector of numbers. Use the following workaround to calculate the mode.
x <- table(Table6)
names(x)[which(x==max(x))]
## [1] "Back"
Beware that this calculation is a workaround and does not work if there is no mode. For example, if we have a vector of 10 unique numbers (like Example 8 in the text), since each data value only occurs once, there is no mode. This workaround calculation does not understand that and will still return every data value as the mode.
A second option for finding the mode is to build a frequency distribution of the raw data and find the most popular value. This requires the Mosaic package.
install.packages("mosaic")
library(mosaic)
tally(~Location,data=Table6)
## Location
## Back Elbow Groin Hand Hip Knee Neck Shoulder
## 12 1 1 2 2 5 1 4
## Wrist
## 2
The most popular location is Back.