Write the following calculations in the text editor.
Run them by either clicking the Run
button in the top-right corner of the editor or press Ctrl+Enter
(Windows & Linux) or Command+Enter (Mac) to run code and print the results in the console.
If no code is highlighted/selected this will run the line the cursor is on. If you highlighted/selected a block of code it will run that entire group of lines.
You can also run the entire script by clicking the arrow next to Source
and selecting Source with Echo
or by using Ctrl+Shift+Enter
(Windows & Linux) or Command+Shift+Enter (Mac).
To tell someone reading the code what this section of the code is about,
add a comment line that says ‘Exercise 1’ before the code that answers
the exercise. Comments in R are added by adding the #
sign.
Anything after a #
sign on the same line is ignored when the program is
run. So, the start of your program should look something like:
# Exercise 1
#1.1
2 - 10
#1.2
3 * 5
Save the script with an informative name, e.g., 2023-01-30-exercise-1.R