WORKSHEET 4 (5 questions)
1. Use the ¡®mtcars¡¯ dataset for the following exercises.
a. Plot Miles/(US) gallon versus Rear axle ratio using the plot() function.
b. On one chart, produce side-by-side boxplots to compare of miles per gallon to
number of gears. Use suitable colors, add a heading and include horizontal and
vertical labels.
2.
a. Using the matrix function, construct a 5×3 matrix, this matrix should consist of
15 evenly spaced points on [0,1] (including the end points). Which is the
default option, by column or by row? Fill the matrix by the default option.
b. Extract the elements in column 1.
c. Extract the element in row 3, column 1.
3. Let:
a <- c(1,2,3)
b <- c(6,7,8)
Write one line of code to generate the following result. Do NOT use the matrix function matrix() (hint: rbind() or cbind()?)
4. Generate an array of two 3x4 matrices from a vector containing the elements 1 through 20 (notice how the elements are recycled).
a. Use the apply function, find the column sums of the array.
b. What does the margin c(1,2) do?
5.
a. In RStudio datasets, find the dataset with the name HairEyeColor. View the dataset.
b. Write code to determine:
i. the total number of respondents in the survey.
ii. the total number of Male respondents in the survey.
iii. How many respondents have blue eyes?
iv. How many Females have red hair?
END WORKSHEET 4