Introduction to R: Exercises


3. Arithmetic operators. The following operators can be used to perform basic arithemtic operations in R:

  • + : addition
  • - : subtraction
  • * : multiplication
  • / : division
  • ^ : exponentiation

Complete the exercises below by applying the correct operator.


X <- 3 Y <- 6 # Multiply 3 by 4. 3___4 # Square the variable X. ___ # Divide Y by X. ___ # Raise Y to the (X-3) power. Y^___ # Multiply 3 by 4. 3*4 # Square the variable X. X^2 # Divide Y by X. Y/X # Raise Y to the (X-3) power. Y^(X-3) test_error() test_output_contains("3*4", incorrect_msg="Recall that you can use the `*` operator to perform multiplication.") test_output_contains("X^2", incorrect_msg="Recall that you can use the `^` operator to perform exponentiation.") test_output_contains("Y/X", incorrect_msg="Recall that you can use the `/` operator to perform division.") test_output_contains("Y^(X-3)", incorrect_msg="Recall that you can use the `^` operator to perform exponentiation.") success_msg("Excellent work!")
Review the list of operators if you are unsure which to apply.

Previous Exercise Next Exercise