[1] 20
Making choices if statements in functions.qmd (solution)
NoteExercise
- Write a function named
double_if_smallthat 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 with10as the input. - Call the function from (1) with
30as the input. - Write a function called
predictionthat takes a single argumentx. Ifxis both greater than 0 and less than 15 then returny = 6 + 0.8 * x. Ifxis both greater than 15 and less than 30 then returny = 5 + 0.75 * x. In all other cases returny = NA. Call the function with5as the input. - Call the function from (3) with
26as the input. - Call the function from (3) with
-2as the input.
CautionOutput solution
1
2
[1] 30
3
[1] 10
4
[1] 24.5
5
[1] NA