[1] 10
Making choices basic if statements.qmd (solution)
1. Complete (i.e., copy into your code and then modify) the following if statement so that if age_class is equal to “sapling” it sets y <- 10.
age_class = "sapling"
if (){
}
y2. Complete the following if statement so that if age_class is equal to “seedling” it sets y <- 5.
age_class = "seedling"
if (){
}
y3. 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.
age_class = "seedling"
if (){
}
y4. 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.
age_class = "adult"
if (){
}
y5. Complete the following if statement so that if size is greater than 100 it sets species <- "DS", if size is between 40 and 60 it sets species <- "DM", and if size is between 10 and 30 it sets species <- "PP". If size doesn’t match any of these conditions set species <- "Unknown".
size = 19
if (){
}
species[1] 5
[1] 5
[1] 0
[1] "PP"