Mathematical operators
get_help()
docs
Mathematical operators (symbols to do math with) in R
include the following:
Operator | What it does |
---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
^ |
Exponentiation |
** |
Exponentiation (no space in between the ** ) |
%% |
Modulo: Find the remainder from “long division” |
All operators can be used on individual numbers or with numeric arrays.
# Add two numbers
5+8
## [1] 13
# Subtract two numbers
5-8
## [1] -3
# Divide two numbers
5/8
## [1] 0.625
# Multiply two numbers
5*8
## [1] 40
# Raise 5 to the 8th power
5^8
## [1] 390625
# Raise 5 to the 8th power
5**8
## [1] 390625
# Find the remainder of 8 divided by 5
8 %% 5
## [1] 3
# Add the number 5 to every value in a numeric array
5 + c(45, 65, 85, 105)
## [1] 50 70 90 110
# Cube every number in a numeric array
c(45, 65, 85, 105)^3
## [1] 91125 274625 614125 1157625