Create data in R

Use R as a calculator

You can start learning R by using it as a simple calculator. Let’s enter some basic formulae

The symbols used for simple arithmetic are the same in R as they are in Excel:

  • Addition+
  • Subtraction -
  • Multiplication *
  • Division /
  • To the power of ^
1 + 1
[1] 2
28 / 7
[1] 4

Mathematical functions

Base R includes all the standard mathematical functions:

sqrt(9)
[1] 3
log(10)
[1] 2.302585

Add comments and notes

If you want to add notes to your script, to help you remember what the code does, type a # symbol before your note. R ignores anything written on a line after the #

# This is a comment - note that it starts with a '#' and R does nothing with it