HW 8
(Based on Vectors (Mode))
1) What is the mode of a dataset? How does it di er from the mean and median?
MODE:
The mode is the value that appears most frequently in a dataset. It's the most common
value or the value with the highest frequency. A dataset can have one mode (unimodal),
two modes (bimodal), or multiple modes (multimodal).
DIFFERENCE OF MEAN,MEDIAN,MODE!
- Mean: The mean, also known as the average, is the sum of all values divided by the
number of values. It's sensitive to extreme values (outliers) and can be influenced by
skewness in the data.
- Median: The median is the middle value in a dataset when it's sorted in ascending or
descending order. It's more robust to outliers than the mean and provides a better
representation of the data's central tendency when the data is skewed.
- Mode: The mode, as mentioned earlier, is the most frequently occurring value in the
dataset. It's not a ected by extreme values or skewness, but it may not provide a
complete picture of the data's central tendency.
Key di erences:
- The mode is based on frequency, while the mean and median are based on the values
themselves.
- The mode can be useful for categorical or discrete data, while the mean and median
are more suitable for continuous data.
- A dataset can have multiple modes, but only one mean and median.
In summary, the mode provides a di erent perspective on the data's central tendency,
highlighting the most common value, whereas the mean and median focus on the
average and middle values, respectively.
2) Write an R function to compute the mode of a given numeric vector. Use the
following dataset:
vec <- c(4, 5, 6, 7, 5, 8, 5, 9, 10, 6, 6)
3) Given the character vector:
colors <- c("red", "blue", "green", "blue", "yellow", "red", "blue")
Write an R script to find the most frequently occurring color.
4) Create a vector representing student grades (A, B, C, D, F) for a class of 25
students with some repeated values. Find the most common grade using R.
5) Simulate rolling a fair six-sided die 500 times and determine which number
appeared most frequently using R.