Chapter 4 Using R as a calculator
The first thing to know about the R console is that you can use it as a calculator.
4.1 Arithmetic Operators
- Additions and Subtractions
1 + 1
## [1] 2
10 - 1
## [1] 9
- Multiplications and Divisions
2 * 2
## [1] 4
8/2
## [1] 4
- Exponents
2^3
## [1] 8
4.1.2 CHALLENGE 3
Use R to calculate the following skill testing equation:
\(2 + 16 * 24 - 56 / (2 + 1) - 457\)
Pay attention to the order of operations when thinking about this question!
Solution
2 + 16 * 24 - 56/(2 + 1) - 457
## [1] -89.66667
Note that R always follows the order of priorities.
R TIP
Try using the “up” and “down” arrows to reproduce previous commands. These keys actually allow you to scroll through your command history. This is a useful tool to go back and see what command you ran and if you might have made a mistake in it. This is always a useful tool to quickly alter previous commands you ran and to re-run them in a slightly different way.