Chapter 1 Introduction

1. Install R and Rstudio on your computer. (Find help in Chapter 1.1)

 

2. Compute \(\frac{74+5}{(2 \cdot 3)^5}\) and assign the name calculation to the result. Print calculation to the console. (Find help in Chapter 1.4 and Chapter 1.5)

 

3. Define a vector months containing the numbers 29, 63, 7, 23, 84, 10 and 9. Compute a vector years from it by dividing months by 12. Print years to the console. (Find help in chapter 1.6.1)

 

4. Check whether the string “R rules!” is equal to “r rules!” for R. (Find help in chapter 1.6.1)

 

5. In a fictitious medical study patients should be excluded from the study if they weigh more than 90 kg or if they are either younger than 18 years or older than 60 years. Define the variable age as age <- c(50, 17, 39, 27, 90) and the variable weight as weight <- c(80, 75, 92, 105, 60). Then write a logical statement involving these two variables that tests for the exclusion criteria. (Find help in chapter 1.6.1)

 

6. The data set Orange contains information on the age in days and trunk circumference in mm of orange trees. Load it into you workspace with data(Orange) and have a look at it with View(Orange). Create a vector called average.growth by dividing the circumference by the age and print it to the console. (Find help in chapter 1.6.3)

 

7. Create a list called x which has the objects calculation, Orange and years from the previous exercises as its elements. What class of objects do you get when you type x[2] as opposed to x[[2]]? (Find help in chapter 1.6.4 and chapter 1.6.5)

 

8. Create a subset of months from the previous exercises containing all elements that constitute less than 6 years. You can do this by using a logical statement involving years within the square brackets [] used for subsetting. (Find help in chapter 1.6.3 and chapter 1.6.1)