Operators are used to perform operations on variables and values.
1) Arithmetic operators are used with numeric values to perform common mathematical operations.
2) Assignment operators are used to assign values to variables.
my_var <- 3
my_var <<- 3
3 -> my_var
3 ->> my_var
## x <- 3 is equal to 3 -> x
## Note: <<- is a global assigner.
3) Comparison operators are used to compare two values.
4) Logical operators are used to combine conditional statements.
x <- c(TRUE, FALSE, TRUE)
y <- c(FALSE, TRUE, TRUE)
x & y
## Output:
[1] FALSE FALSE TRUE
x <- 5
if (x > 0 && x < 10)
{
print("x is positive and less than 10")
}
else
{
print("x is either negative or greater than 10")
}
## Output:
[1] "x is positive and less than 10"
5) Miscellaneous operators are used to manipulate data