Exercise 1: Base R
After working through Exercise 1, you’ll…
- have assessed how well you know R and RStudio
- know what chapters and concepts you might want to repeat again
- have managed to apply the basic concepts of R to data
Task 1
Below you will see multiple choice questions. Please try to identify the correct answers. 1, 2, 3 and 4 correct answers are possible for each question.
1. What panels are part of RStudio?
- source
- console
- input
- packages, files & plots
2. How do you activate R packages after you have installed them?
- import.packages()
- install.packages()
- package()
- library()
3. How do you create a vector in R with elements 1, 2, 3?
- cbind(1,2,3)
- cb(1,2,3)
- c(1,2,3)
- cmb(1,2,3)
4. Imagine you have a vector called ‘vector’ with 10 numeric elements. How do you retrieve the 8th element?
- vector[-2]
- vector[„-2”]
- vector[8]
- vector[„8”]
5. Imagine you have a vector called ‘hair’ with 5 elements: brown, black, red, blond, other. How do you retrieve the color ‘blond’?
- hair[4]
- hair[„4”]
- hair[blond]
- hair[„blond”]
Task 2
Create a numeric vector with 8 values and assign the name age to the vector. First, display all elements of the vector. Then print only the 5th element. After that, display all elements except the 5th. Finally, display the elements at the positions 6 to 8.
Task 3
Create a non-numeric, i.e. character, vector with 4 elements and assign the name eye_color to the vector. First, print all elements of this vector to the console. Then have only the value in the 2nd element displayed, then all values except the 2nd element. At the end, display the elements at the positions 2 to 4.
When you’re ready to look at the solutions, you can find them here:Solutions for Exercise 1.