Making choices basic if statements.qmd (solution)

Exercise
Output solution
  1. Complete (i.e., copy into your code and them modify) the following if statement so that if age_class is equal to “sapling” it sets y <- 10.
[1] 10
  1. Complete the following if statement so that if age_class is equal to “sapling” it sets y <- 10 and if age_class is equal to “seedling” it sets y <- 5.
[1] 5
  1. Complete the following if statement so that if age_class is equal to “sapling” it sets y <- 10 and if age_class is equal to “seedling” it sets y <- 5 and if age_class is something else then it sets the value of y <- 0.
[1] 0

4. Convert your conditional statement from (3) into a function that takes age_class as an argument and returns y. Call this function 5 times, once with each of the following values for age_class: “sapling”, “seedling”, “adult”, “mature”, “established”.

[1] 10
[1] 5
[1] 0
[1] 0
[1] 0