Base Data Types
Numeric 1, 100, 21.2All numbers: Integer, Double etc. (R automatically converts)
Integer 1L, 23LExplicit integer notation
Complex 5 + 7i
Logical TRUE, FALSE
Character 'a', "SyntaxNut"The String data format
Raw 28 41Raw bytes
Container Types
Vector v1 <- c(1, 2, 3)
List l1 <- list(c(1,2,3), 'a', sum)
Matrix m1 <- matrix(c(1,2,3,4,5,6,7,8,9), nrow = 3, ncol = 3, byrow = TRUE)
Array a1 <- array(c(1,2,3), dim(5,5,2))
Factor f1 <- factor(c('factor1', 'factor2', 'factor3', 'factor1', 'factor2'))
Data Frame df1 <- data.frame(type = c("Volvo", "BMW"), cost = c(123, 456))
Flow Control
if / else / else if
if (boolean expression) {
    // statements
} else if (boolean expression) {
    // statements
} else {
    // statements
}
while
while (boolean expression) {
    // statements
}
repeat
repeat {
    // statements
    if (boolean expression) {
        break
    }
}
for loop
for ( name in vector ) {
    // statements
}
switch / default
result <- switch(value,
    "1" = "Result1",
    "2" = "Result2",
    "DefaultResult")
try catch / finally
result <- trycatch({
        // statements
    },
    error=function(condition) {
        // statements
        return(NULL)
    }
    warning=function(condition) {
        // statements
        return(NULL)
    },finally = {
        // statements
    })
function
function <- function(param) {
    //statements
    return(value)
}
Hello World
print("Hello world!")
Logical Operators
Comparisons <, <=,>, >=, ==, !=
And && Short circuits.
& Each vector element / No short-circuiting
Or || Short circuits.
| Each vector element / No short-circuiting
Negate !(boolean expression)
Arithmetic Operators
Add +
Subtract -
Multiply *
Divide /
Modulus %%
Integer Division %/%Floors extra decimals
Exponent ^