In its most basic form, R can be used as a simple calculator. Consider the following arithmetic operators:
+
-
*
/
^
%%
The last two might need some explaining:
^
operator raises the number to its left to the power of the number to its right: for example 3^2
is 9.5 %% 3
is 2.With this knowledge, follow the instructions below to complete the exercise.
2^5
in the editor to calculate 2 to the power 5.28 %% 6
to calculate 28 modulo 6.#
symbol is used to add comments on the R code.
# An addition
5 + 5
# A subtraction
5 - 5
# A multiplication
3 * 5
# A division
(5 + 5) / 2
# Exponentiation
# Modulo
# An addition
5 + 5
# A subtraction
5 - 5
# A multiplication
3 * 5
# A division
(5 + 5) / 2
# Exponentiation
2 ^ 5
# Modulo
28 %% 6
msg = "Do not remove the other arithmetic examples!"
test_output_contains("2^5", incorrect_msg = "The exponentiation example is not correct. Write `2 ^ 5` on a new line.")
test_output_contains("28 %% 6", incorrect_msg = "There seems to be an issue with the modulo example. Write `28 %% 6` on a new line.")
success_msg("Great! Head over to the next exercise.")