Making choices if statements in functions.qmd (solution)

Exercise
  1. Write a function named double_if_small that takes a number as input and returns the number multiplied by 2 if the input is less than 26 and returns just the number (not multiplied by two) if the input is greater than or equal to 26. Call the function with 10 as the input.
  2. Call the function from (1) with 30 as the input.
  3. Write a function called prediction that takes a single argument x. If x is both greater than 0 and less than 15 then return y = 6 + 0.8 * x. If x is both greater than 15 and less than 30 then return y = 5 + 0.75 * x. In all other cases return y = NA. Call the function with 5 as the input.
  4. Call the function from (3) with 26 as the input.
  5. Call the function from (3) with -2 as the input.
Output solution

1

[1] 20

2

[1] 30

3

[1] 10

4

[1] 24.5

5

[1] NA