Question 1
Which of the following lines of code would allow a user to install a package?
1. install.packages(ggplot2)
2.
... [Show More] install.packages("ggplot2")
3. library("ggplot2")
4. library(ggplot2)
Question 2
What would the following lines of code is equivalent to the bolded line shown immediately
below?
> a <- 8
1. a>=8
2. a = 8
3. a<=8
4. a is not equel to 8
Question 3
Which sequence is necessary to use the R package crayon in your current environment, if never
previously used?
1. library("crayon") → install("crayon")
2. download("crayon") → import.crayon
3. install.packages("crayon") → library("crayon")
4. install.package("crayon") → import("crayon")
Question 4
Which of the following statement is true?
1. The data stored in a frame can only be numeric or character
2. A data frame is a table in which each column contains values of more than one variable and
each row contains only one variable
3. The name of the rows can be same
4. The column names in a data frame cannot be empty
Question 5
[To answer this question, you can use information from the unit or you may enter the code
directly into your R Console. Please don’t think you’d be cheating if you just type the code in
directly to answer the question -- in fact, we encourage it!]
A user creates a vector called stocks with the following code:
> stocks <- c( GE , T , AAPL , VZ , MMM , JNJ )
What will the following line of code return in the console?
> length(stocks)
1. GE, T, AAPL, VZ, MMM, JNJ
2. AAPL
3. 6
4. 5
Question 6
Which of the following can be used to select one or multiple elements from a matrix?
1. Quotation marks
2. Selection function
3. Square brackets
4. Parentheses
Question 7
The iris dataset is built into the base package in R. It contains data about the petal length, petal
width, sepal length, and sepal width of 150 iris flowers of three species (setosa, versicolor, and
virginica. In RStudio, enter the following line of code into the console (type everything after the
prompt, which is represented by the greater than sign):
> dim(iris)
What is displayed in the console when you enter this command?
1. [1] 150 5
2. [1] 5 150
3. [1] 5 85
4. [1] 3 150
Question 8
The iris dataset is built into the base package in R. It contains data about the petal length, petal
width, sepal length, and sepal width of 150 iris flowers of three species (setosa, versicolor, and
virginica. Using R Studio, find the standard deviation of iris petal width, by typing
sd(iris$Petal.Width).
1. 0.7622377
2. 0.8157157
3. 0.5155109
4. 0.1856191
Question 9
You are working with a data frame called songlist. Frustratingly, you find that many of the values
in songlist simply appear as NA (Not Available).
What would happen if you were to type the following code into the console?
> na.omit(songlist)
1. All of the missing values would then be labeled as 0 rather than NA.
2. The console would deliver a list of rows that contained missing values.
3. In the console, the value TRUE would appear (since there are definitely at least some missing
values).
4. Any rows in songlist that contained missing data would be removed from the data frame.
Question 10
[To answer this question, you can use information from the unit or you may enter the code
directly into your R Console. Please don t think you d be cheating if you just type the code in
directly to answer the question -- in fact, we encourage it!]
First, in your R console, type in the following code:
> hist(mtcars$mpg)
Observe your results. Now, type in this line of code:
> hist(mtcars$mpg, breaks=15)
What changed when you ran the second line of code (as compared to the first line)?
1. The second time, there were more bins (categories) shown in the histogram.
2. The second histogram appeared broken which meant that it was split across two different
panels.
3. The second histogram was outlined in blue, whereas the first was outlined in the default color
(black).
4. In the second histogram, the mpg variable was converted from a continuous numeric input to
a factor.
Question [Show Less]