# Week 3 Quiz >> R Programming

## Week 3 Quiz >> R Programming

1. Take a look at the ‘iris’ dataset that comes with R. The data can be loaded with the code:

`library(datasets) data(iris)`

A description of the dataset can be found by running

`?iris`

There will be an object called ‘iris’ in your workspace. In this dataset, what is the mean of ‘Sepal.Length’ for the species virginica? Please round your answer to the nearest whole number.
(Only enter the numeric result and nothing else.)

`7 ✅`

2. Continuing with the ‘iris’ dataset from the previous Question, what R code returns a vector of the means of the variables ‘Sepal.Length’, ‘Sepal.Width’, ‘Petal.Length’, and ‘Petal.Width’?

• apply(iris, 2, mean)
• colMeans(iris)
• apply(iris[, 1:4], 2, mean)
• apply(iris, 1, mean)
• apply(iris[, 1:4], 1, mean)
• rowMeans(iris[, 1:4])

3. Load the ‘mtcars’ dataset in R with the following code

`library(datasets) data(mtcars)`

There will be an object names ‘mtcars’ in your workspace. You can find some information about the dataset by running

`?mtcars`

How can one calculate the average miles per gallon (mpg) by number of cylinders in the car (cyl)? Select all that apply.

• with(mtcars, tapply(mpg, cyl, mean))
• tapply(mtcars\$mpg, mtcars\$cyl, mean)
• apply(mtcars, 2, mean)
• tapply(mtcars\$cyl, mtcars\$mpg, mean)
• sapply(split(mtcars\$mpg, mtcars\$cyl), mean)
• sapply(mtcars, cyl, mean)
• split(mtcars, mtcars\$cyl)
• lapply(mtcars, mean)
• mean(mtcars\$mpg, mtcars\$cyl)

4. Continuing with the ‘mtcars’ dataset from the previous Question, what is the absolute difference between the average horsepower of 4-cylinder cars and the average horsepower of 8-cylinder cars?
(Please round your final answer to the nearest whole number. Only enter the numeric result and nothing else.)

`127`

5. If you run

`debug(ls)`

what happens when you next call the ‘ls’ function?

• You will be prompted to specify at which line of the function you would like to suspend execution and enter the browser.
• Execution of ‘ls’ will suspend at the beginning of the function and you will be in the browser.
• The ‘ls’ function will return an error.
• The ‘ls’ function will execute as usual.