1.6 R as a calculator
R can be used as a calculator to carry out many different operations. Try each of the following.
5 + 5
## [1] 10
5 - 3
## [1] 2
4 * 4
## [1] 16
7 / 2
## [1] 3.5
5 + 3) / 2 (
## [1] 4
3^2 # Raising to a power
## [1] 9
sqrt(4)
## [1] 2
8^(1/3) # Use the inverse of 3 to get the cube root
## [1] 2
log(100) # Natural logarithm (base e = 2.71828...)
## [1] 4.605
log(100, base = 10) # You can change the base
## [1] 2
log10(100) # Some bases have their own function
## [1] 2
log2(100)
## [1] 6.644
exp(1) # Exponentiate
## [1] 2.718
abs(-5) # Absolute value
## [1] 5