R language: A Quick Reference is about learning R Programming with a short description of the widely used commands. It will help the learner and intermediate user of the R Programming Language to get help with different functions quickly. This Quick Reference is classified into different groups. Let us start with R Language: A Quick Reference – I.

### Basic Data Representation

In the R Language, data values or data may be represented as logical values (Such as True, or False), in scientific notation, as a complex, or as a float number. The are some certain values such as NA, NULL, NaN, and Inf values.

R Command | Short Description |
---|---|

True, False | Logical true or false |

1.23e10 | A number in scientific notation $1.23\times 10^{20}$ |

3.4i | A complex number |

“Hello” | A String/ Characters |

NA | Missing Value representation (in any type of vector) |

NULL | Missing Value indicator in lists |

NaN | Not a number |

-Inf | Negative Infinity |

Inf | Positive infinity |

### Checking/ Testing the Basic Data Types

The type of data can be checked using some functions such as is.logical(), is.numeric(), is.list(), is.character(), is.vector() or is.complex() function.

R Command | Short Description |
---|---|

is.logical(x) | Results in true for logical vectors |

is.numeric(x) | Results in true for numeric vectors |

is.character(x) | Results in true for character vectors |

is.list(x) | Results in true for lists |

is.vector(x) | Results in true for both lists and vectors |

is.complex(x) | Results in true for complex vectors |

### Checking/ Testing the Special Values

The type of special values can be checked using is.na(), is.nan(), is.finite(), is.ordered(), and is.factor() etc., functions

R Command | Short Description |
---|---|

is.na(x) | Results in true for elements that are NA or NaN |

is.nan(x) | Results in true for elements that are NaN |

is.null(x) | Results in true whether $x$ is NULL |

is.finite(x) | Results in true for finite elements (e.g., not NA, NaN, Inf or -Inf) |

is.infinite(x) | Results in true for elements equal to Inf or -Inf |

is.factor(x) | Results in true for a factors and ordered factors |

is.ordered(x) | Results in true for ordered factors |

### Changing Basic Data Type

The type of data can be changed by using functions such as, as.logical(), as.numeric(), as.list(), or as.numeric() etc., functions.

Type Coercion | Short Description |
---|---|

as.logical(x) | Coerces to a vector (However, lists remain lists) |

as.numeric(x) | Coerces a vector to a numeric vector |

as.character(x) | Coerces a vector to a character vector |

as.list(x) | Coerces a vector to a list |

as.vector(x) | Coerces to a vector (However, lists remains lists) |

unlist(x) | Converts a list to a vector |

as.complex(x) | Coerces to a vector (However, lists remain lists) |

### Basic Mathematical Operations

R can be used as a calculator. The mathematical operations such as addition, subtraction, multiplication, and division can also be performed.

Basic Math Operation | Short Description |
---|---|

x + y | Perform addition between the $x$ and $y$ vector |

x – y | Perform subtraction between the $x$ and $y$ vector |

x * y | Perform multiplication between the $x$ and $y$ vector |

x / y | Perform division between the $x$ and $y$ vector |

x ^ y | Perform exponentiation, “$x$ raised to power $y$” |

x %% y | Computes remainder, “$x$ modulo $y$” |

x %/% y | Performs Integer division, “$x$ divided by $y$”, discard the fractional part |

## Rounding off the Numbers

The numbers or values of a variable can be rounded as desired.

R Command | Short Description |
---|---|

round(x) | Round down the values of a variable to the next lowest integer |

round(x, d) | Round the values of a variable $x$ to the $d$ decimal places |

signif(x, d) | Round the values of a variable $x$ to $d$ significant digits |

floor(x) | Round down the values of a variable to next lowest integer |

ceiling(x) | Round up the values of a variable to the highest integer |

### Common Mathematical Functions

The commonly used mathematical functions in R language are abs(), sqrt(), exp(), log(), and different bases of log functions.

R Command | Short Description |
---|---|

abs(x) | Absolute values |

sqrt(x) | Computes the square root of the values of a variable |

exp(x) | Computes $e^x$ |

log(x) | Computes the log values of the variable $x$ |

log10(x) | Computes the log base 10 (common log) of the variable $x$ |

log2(x) | Computes the log base 2 of the variable $x$ |

log(x, base=b) | Computes the log base $b$ of the variable $x$ |

### Trigonometric and Hyperbolic Functions

Following is the list of different trigonometric and Hyperbolic functions

Trigonometric Functions | Short Description |
---|---|

sin(x), cos(x), tan(x) | Computes the trigonometric values, sin, cos, and tan of a vector $x$ |

asin(x), acos(x), atan(x) | Computes the inverse trigonometric values of a vector $x$ |

atan2(x, y) | Computes arc tangent with two arguments |

sinh(x), cosh(x), tanh(x) | Computes hyperbolic values of a vector $x$ |

asinh(x), acosh(x), atanh(x) | Computes the inverse hyperbolic values of a vector $x$ |

### Special Mathematical Functions

The following is the list of special mathematical functions.

Mathematical Functions | Short Description |
---|---|

beta(x, y) | The beta function |

lbeta(x, y) | The log beta function |

gamma(x) | The gamma function |

lgamma(x) | The log gamma function |

psigamma(x, deriv = 0) | The psigamma function |

digamma(x) | The digamma function |

trigamma(x) | The trigamma function |