Variable names
Examples
x1
, x1.a
.abc
this_is_an_informative_variable_name.v1
another.style.of.a.name
orEvenThisWay
Data types
numeric()
character()
logical()
integer()
complex()
Assign a value to a variable:
a <- value
a = value
Operators
+
, -
, *
, ^
, /
, x %% y
, …|
(or), &
(and), !
(not), ==
, <
, <=
, >
, >=
, …[
, e.g., x[c(2, 3)]
[<-
, e.g., x[c(1, 3)] <- c(4, 5)
is.na()
, as.character()
, …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