Variable names

Examples

Data types

Assign a value to a variable:

Operators

Operations

5 + 4
## [1] 9
3^2
## [1] 9
x = 5
y = 2
x^2
## [1] 25
x/y
## [1] 2.5
2*x
## [1] 10
sin(x*y)
## [1] -0.5440211

Vectorized operations

x <- 1:3        # sequence of integers from 1 to 3
y <- c(2,4,7)
x; y; x + y     # separate commands by semicolon
## [1] 1 2 3
## [1] 2 4 7
## [1]  3  6 10
x + 4           # recycling
## [1] 5 6 7