R Language: A Quick Reference – I

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
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
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
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
Type Coercion | Short Description |
---|---|
as.logical(x) | Coerces a vector to logical vector |
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
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
R Command | Short Description |
---|---|
round(x) | Round the values of a variable to nearest 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
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
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
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 |