Mathematical
# Addition
> 2+2
[1] 4
# Multiplication
> 2*3
[1] 6
# Division
> 4/2
[1] 2
# Power
> 2^3
[1] 8
Logical
?base::logic
| & | boolean and |
| | | boolean for |
| xor | exactly or |
| ! | not |
| any | any true |
| all | all true |
- Not (!)
> !TRUE
[1] FALSE
Many operations in R are vectorized.
> x=1:4;y=6:3
> x
[1] 1 2 3 4
> y
[1] 6 5 4 3
# Logical
> x>2
[1] FALSE FALSE TRUE TRUE
> x>=2
[1] FALSE TRUE TRUE TRUE
> y==1
[1] FALSE FALSE FALSE FALSE
Comparison
?Comparison
| < | Less than |
| > | Greater than |
| == | Equal to |
| ⇐ | Less than or equal to |
| >= | Greater than or equal to |
| != | Not equal to |
| %in% | Group membership |
| is.na | Is NA |
| !is.na | Is not NA |
Assignment
The symbol ← and = are the assignment operator.
x <- 1
is equivalent to:
x = 1
Proof:
> x<-1
> y=1
> x==y
[1] TRUE
Sequence
The : operator is used to create integer sequences.
> x=3:5
> x
[1] 3 4 5
Subset
R - Subset Operators (Extract or Replace Parts of an Object)
