I Exam
Last updated: 2020-08-12 00:41:58
I.1 Course grade
- Exercises (50%)
- Exam (50%)
- The exam is composed of 20 multiple-choice questions. There is exactly one right answer to each question.
- Exam duration is 3 hours.
- Permitted exam equipment: a calculator.
- The exam takes place in a regular class, with pen and paper (not in front of a computer).
- Each question gives a short code section. The code section is not identical to the ones that appeared in the course materials, but they combine functions and methods which were learned. You need to choose the right code output out of 4 options.
I.3 Examples of exam questions
I.3.1 Question 1
What will be the output of the following code section?
()
[1] NA NA NA
()
[1] 3 2 4
()
[1] NA -2 8
()
[1] NA -1 2
I.3.2 Question 2
What will be the output of the following code section?
()
[1] 1 2
()
[1] 2 1
()
[1] 1 1
()
[1] 2
I.3.3 Question 3
What will be the output of the following code section?
()
[1] 1 2 1 2
()
[1] 1 2 3 4
()
[1] 1 2
()
[1] 1 4 1 4
I.3.4 Question 4
What will be the output of the following code section?
()
[1] FALSE
()
[1] TRUE TRUE TRUE
()
[1] TRUE FALSE
()
[1] TRUE
I.3.5 Question 5
What will be the output of the following code section?
()
[1] FALSE FALSE FALSE FALSE
()
[1] TRUE FALSE FALSE FALSE
()
[1] TRUE TRUE FALSE FALSE
()
[1] TRUE TRUE TRUE FALSE
I.3.6 Data for questions 6-8
For questions 6-8 we define a stars
raster named r
, and an sf
point layer named pnt
:
library(sf)
library(stars)
v = c(10,7,4,1,8,5,9,3,9,8,4,2,5,7,1,9,6,3)
a = array(v, dim = c(3, 3, 2))
r = st_as_stars(a)
r = st_set_dimensions(r, names = c("x", "y", "layer"))
r = st_set_dimensions(r, "y", delta = -1, offset = 3)
r = st_set_dimensions(r, "y", point = FALSE)
r = st_set_dimensions(r, "layer", values = c("one", "two"))
names(r) = "var"
r
## stars object with 3 dimensions and 1 attribute
## attribute(s):
## var
## Min. : 1.000
## 1st Qu.: 3.250
## Median : 5.500
## Mean : 5.611
## 3rd Qu.: 8.000
## Max. :10.000
## dimension(s):
## from to offset delta refsys point values
## x 1 3 0 1 NA FALSE NULL [x]
## y 1 3 3 -1 NA FALSE NULL [y]
## layer 1 2 NA NA NA FALSE one, two
pnt = data.frame(x = c(1.6, 0.2), y = c(1.7, 2.6), z = c(80, 90))
pnt = st_as_sf(pnt, coords = c("x", "y"))
You can also learn about the structure of r
from the following plot.
I.3.7 Question 6
What will be the output of the following code section?
()
[1] 0 3
()
[1] 1 3
()
[1] 0 2
()
[1] 1 2
I.3.8 Question 7
What will be the output of the following code section?
()
[1] 1.222222
()
[1] 1.444444
()
[1] 1.888888
()
[1] 1
I.3.9 Question 8
What will be the output of the following code section?
()
[1] 1
()
[1] 56
()
[1] 8
()
[1] 101
I.3.10 Question 9
What will be the output of the following code section?
()
[1] NA
()
[1] 1
()
[1] 2
()
[1] 3
I.3.11 Data for questions 10-11
For questions 10-11 we will define two data.frame
objects named animals
and types
:
I.3.12 Question 10
What will be the output of the following code section?
()
[1] 0
()
[1] 1
()
[1] 2
()
[1] 3
I.3.13 Question 11
What will be the output of the following code section?
()
[1] "cat cat" "sparrow cat" "turtle cat"
()
[1] "sparrow sparrow"
()
[1] "sparrow"
()
[1] "sparrow cat"
I.3.14 Question 12
What will be the output of the following code section?
()
[1] 1
()
[1] 2
()
[1] 5
()
[1] 6
I.3.15 Question 13
What will be the output of the following code section?
()
[1] FALSE
()
[1] TRUE
()
[1] TRUE TRUE TRUE
()
[1] FALSE FALSE FALSE
I.3.16 Data for questions 14-15
For questions 14-15 we will define a data.frame
object named cars
. (All columns are numeric
.)
cars = mtcars[1:10, 1:4]
cars
## mpg cyl disp hp
## Mazda RX4 21.0 6 160.0 110
## Mazda RX4 Wag 21.0 6 160.0 110
## Datsun 710 22.8 4 108.0 93
## Hornet 4 Drive 21.4 6 258.0 110
## Hornet Sportabout 18.7 8 360.0 175
## Valiant 18.1 6 225.0 105
## Duster 360 14.3 8 360.0 245
## Merc 240D 24.4 4 146.7 62
## Merc 230 22.8 4 140.8 95
## Merc 280 19.2 6 167.6 123
I.3.17 Question 14
What will be the output of the following code section?
()
[1] 2 4 1
()
[1] 8 6 5
()
[1] 2 4 6
()
[1] 62 105 175
I.3.18 Question 15
What will be the output of the following code section?
()
[1] 2 4 8
()
[1] 8
()
[1] 4
()
[1] 4 8
I.3.19 Data for questions 16-17
For questions 14-15 we will define a matrix
named m
:
I.3.20 Question 16
What will be the output of the following code section?
()
[1] 6 6 6
()
[1] 1 1 1
()
[1] 1 2 3
()
[1] 2 2 2
I.3.21 Question 17
What will be the output of the following code section?
()
[1] 31
()
[1] 29
()
[1] 28
()
[1] 33