Any sufficiently advanced technology is equivalent to magic.

Top

Site Menu

Arithmetic

R can be used as a calculator to perform simple mathematical operations.

Math Operators

Click the Run button to evaluate these math expressions.

# no pec 4 + 5 5 - 4 4 * 5 5 / 4 4^5
Parentheses can be used similarly to how they are used in mathematics. However, parentheses alone can not be used for multiplication. R needs to have the multiplication symbol, '$*$', before the parenthesis in order to run properly.
Example:
$4(5+1) = 24$ and
$4*(5+1) = 24$ are mathematically equivalent but will return different results when inputted into R.

# no pec 4 * (5 + 1) # Note how this line runs fine. 4(5 + 1) # This line does not run and provides an error.


Example: $\dfrac{2(5+1)^2}{4*3} = 6$

This expression can be evaluated in R:

# no pec 2 * (5 + 1)^2 / (4 * 3)

Math Functions

Click the Run button to evaluate these math functions.

# no pec sqrt(16) exp(2) log(10) # Showing that R does use the natural log log(exp(1)) # Showing how you can use a different base log(25, base = 5)

$\pi$ and Trigonometry

The number $\pi$ is already stored in R as pi.
Click the Run button to evaluate these math expressions.

# no pec pi 2 * pi pi / 2
The trigonometric functions of sine, cosine and tangent are also in R, as sin(), cos(), and tan(), respectively. Angle inputs are to be in radians, not degrees.
Click the Run button to evaluate these math functions.

# no pec sin(pi / 2) cos(2 * pi) cos(pi) tan(pi / 4)

Video Tutorial: