Basics

Nicky Wakim

Coding basics

  • R can be used to do calculations (like a calculator)
  • It will follow the order of operations (PEMDAS) when doing calculations
1 / 200 * 30
[1] 0.15
(59 + 73 + 2) / 3
[1] 44.66667
sin(pi / 2)
[1] 1

Different operators

  • Most operators are the same as in math, but some are different

 

Here are some common operators:

Operation Written In R
Addition \(1+1\) 1+1
Subtraction \(2-1\) 2-1
Multiplication \(3\times 2\) or \(3\cdot 2\) 3*2
Division \(3 / 2\) or \(\dfrac{3}{2}\) 3/2
Exponential \(4^2\) 4^2
Square root \(\sqrt{4}\) or \(4^{1/2}\) 4^(1/2) or sqrt(4)

Relational operators

  • These operators are interpreted as questions

  • R will return a true or false answer, depending on if it meets the criteria

Operation In R
Less than 1<1
Greater than 1>1
Less than or equal to 1<=1
Greater than or equal to 1>=1
Equal to 1==1
Not equal to 1!=1

References