R Coursera Week 1
R Coursera Week 1
Question 1
The R language is a dialect of which of the following programming languages?
1 / 1 point
Java
Haskell
Correct
R is a dialect of the S language which was developed at Bell Labs.
2.
Question 2
The definition of free software consists of four freedoms (freedoms 0 through 3). Which of the
following is NOT one of the freedoms that are part of the definition? Select all that apply.
1 / 1 point
The freedom to study how the program works, and adapt it to your needs.
The freedom to restrict access to the source code for the software.
Correct
This is not part of the free software definition. Freedoms 1 and 3 require access to the source code.
Correct
This is not part of the free software definition. The free software definition does not mention anything
about selling software (although it does not disallow it).
The freedom to improve the program, and release your improvements to the public, so that the
whole community benefits.
The freedom to prevent users from using the software for undesirable purposes.
Correct
This is not part of the free software definition. Freedom 0 requires that the users of free software be
free to use the software for any purpose.
3.
Question 3
In R the following are all atomic data types EXCEPT: (Select all that apply)
1 / 1 point
character
complex
matrix
Correct
'matrix' is not an atomic data type in R.
integer
array
Correct
'array' is not an atomic data type in R.
logical
list
Correct
'list' is not an atomic data type in R.
table
Correct
'table' is not an atomic data type in R.
data frame
Correct
'data frame' is not an atomic data type in R.
numeric
4.
Question 4
If I execute the expression x <- 4 in R, what is the class of the object `x' as determined by the
`class()' function?
1 / 1 point
numeric
complex
vector
real
list
integer
Matrix
Correct
5.
Question 5
What is the class of the object defined by the expression x <- c(4, "a", TRUE)?
1 / 1 point
integer
numeric
logical
mixed
character
Correct
The character class is the "lowest common denominator" here and so all elements will be coerced
into that class.
integer
numeric
logical
matrix
character
list
6.
Question 6
If I have two vectors x <- c(1,3, 5) and y <- c(3, 2, 10), what is produced by the expression cbind(x,
y)?
1 / 1 point
a vector of length 3
a 2 by 2 matrix
a 2 by 3 matrix
a vector of length 2
a 3 by 3 matrix
Correct
The 'cbind' function treats vectors as if they were columns of a matrix. It then takes those vectors
and binds them together column-wise to create a matrix.
7.
Question 7
A key property of vectors in R is that
1 / 1 point
Correct
8.
Question 8
Suppose I have a list defined as x <- list(2, "a", "b", TRUE). What does x[[1]] give me? Select all that
apply.
0 / 1 point
Correct
Question 8
Suppose I have a list defined as x <- list(2, "a", "b", TRUE). What does x[[2]] give me? Select all that
apply.
1 / 1 point
Correct
Correct
9.
Question 9
Suppose I have a vector x <- 1:4 and y <- 2:3. What is produced by the expression x + y?
0 / 1 point
an error.
9.
Question 9
Suppose I have a vector x <- 1:4 and a vector y <- 2. What is produced by the expression x + y?
1 / 1 point
Correct
10.
Question 10
Suppose I have a vector x <- c(17, 14, 4, 5, 13, 12, 10) and I want to set all elements of this vector
that are greater than 10 to be equal to 4. What R code achieves this? Select all that apply.
1 / 1 point
x[x > 10] <- 4
Correct
You can create a logical vector with the expression x > 10 and then use the [ operator to subset the
original vector x.
x[x == 4] > 10
Correct
You can create a logical vector with the expression x >= 11 and then use the [ operator to subset the
original vector x.
11.
Incorrect
10.
Question 10
Suppose I have a vector x <- c(17, 14, 4, 5, 13, 12, 10) and I want to set all elements of this vector
that are greater than 10 to be equal to 4. What R code achieves this? Select all that apply.
1 / 1 point
Correct
You can create a logical vector with the expression x >= 11 and then use the [ operator to subset the
original vector x.
x[x == 4] > 10
Correct
You can create a logical vector with the expression x > 10 and then use the [ operator to subset the
original vector x.
Suppose I have a vector x <- c(3, 5, 1, 10, 12, 6) and I want to set all elements of this vector that are
less than 6 to be equal to zero. What R code achieves this? Select all that apply.
0 / 1 point
x[x == 0] < 6
Correct
You can create a logical vector with the expression x < 6 and then use the [ operator to subset the
original vector x.
x[x < 6] == 0
x[x != 6] <- 0
x[x == 0] <- 6
x[x == 6] <- 0
In the dataset provided for this Quiz, what are the column names of the dataset?
1 / 1 point
1, 2, 3, 4, 5, 6
Month, Day, Temp, Wind
Correct
You can get the column names of a data frame with the `names()' function.
12.
Question 12
Extract the first 2 rows of the data frame and print them to the console. What does the output look
like?
1 / 1 point
2 35 274 10.3 82 7 17
Ozone Solar.R Wind Temp Month Day
1 7 NA 6.9 74 5 11
Ozone Solar.R Wind Temp Month Day
1 9 24 10.9 71 9 14
2 18 131 8.0 76 9 29
Ozone Solar.R Wind Temp Month Day
1 18 224 13.8 67 9 17
2 NA 258 9.7 81 7 22
Ozone Solar.R Wind Temp Month Day
1 41 190 7.4 67 5 1
2 36 118 8.0 72 5 2
ITO YUNG DAY 1,2 TAMA
Correct
You can extract the first two rows using the [ operator and an integer sequence to index the rows.
13.
Question 13
How many observations (i.e. rows) are in this data frame?
1 / 1 point
45
160
129
153
Correct
You can use the `nrows()' function to compute the number of rows in a data frame.
14.
Question 14
Extract the last 2 rows of the data frame and print them to the console. What does the output look
like?
1 / 1 point
3
Ozone Solar.R Wind Temp Month Day
152 11 44 9.7 62 5 20
153 108 223 8.0 85 7 25
153 13 27 10.3 76 9 18
Ozone Solar.R Wind Temp Month Day
152 34 307 12.0 66 5 17
Ozone Solar.R Wind Temp Month Day
152 31 244 10.9 78 8 19
153 29 127 9.7 82 6 7
Ozone Solar.R Wind Temp Month Day
152 18 131 8.0 76 9 29
153 20 223 11.5 68 9 30
Correct
The `tail()' function is an easy way to extract the last few elements of an R object.
15.
Question 15
What is the value of Ozone in the 47th row?
1 / 1 point
34
21
18
63
Correct
The single bracket [ operator can be used to extract individual rows of a data frame.
16.
Question 16
How many missing values are in the Ozone column of this data frame?
1 / 1 point
37
43
78
Correct
The `is.na' function can be used to test for missing values.
17.
Question 17
What is the mean of the Ozone column in this dataset? Exclude missing values (coded as NA) from
this calculation.
1 / 1 point
42.1
53.2
31.5
18.0
Correct
The `mean' function can be used to calculate the mean.
18.
Question 18
Extract the subset of rows of the data frame where Ozone values are above 31 and Temp values are
above 90. What is the mean of Solar.R in this subset?
1 / 1 point
185.9
212.8
205.0
334.0
Correct
You need to construct a logical vector in R to match the question's requirements. Then use that
logical vector to subset the data frame.
19.
Question 19
What is the mean of "Temp" when "Month" is equal to 6?
1 / 1 point
85.6
75.3
79.1
90.2
Correct
20.
Question 20
What was the maximum ozone value in the month of May (i.e. Month is equal to 5)?
1 / 1 point
97
18
100
115
Correct