Skip to main content

Vectors shrub volume vectors (solution)

NoteExercise

You have data on the length, width, and height of 10 individuals of the yew Taxus baccata stored in the following vectors:

shrub_length <- c(2.2, 2.1, 2.7, 3.0, 3.1, 2.5, 1.9, 1.1, 3.5, 2.9)
shrub_width <- c(1.3, 2.2, 1.5, 4.5, 3.1, 2.6, 1.8, 0.5, 2.0, 2.7)
shrub_height <- c(9.6, 7.6, 2.2, 1.5, 4.0, 3.0, 4.5, 2.3, 7.5, 3.2)

Copy these vectors into an R script and then use R to determine the following:

  1. What is the maximum height of a shrub?
  2. What is is the width of the 6th shrub?
  3. How many shrubs are there?
  4. What is the average width of a shrub?
  5. What are the lengths of shrubs 3-5? (look up all values at once, not one at a time)
  6. What is the total height of all shrubs added together?
CautionOutput solution
[1] 9.6
[1] 2.6
[1] 10
[1] 2.22
[1] 2.7 3.0 3.1
[1] 45.4