R Language: A Quick Reference – I

R Programming: A Quick Reference

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 CommandShort Description
True, FalseLogical true or false
1.23e10A number in scientific notation $1.23\times 10^{20}$
3.4iA complex number
“Hello”A String/ Characters
NAMissing Value representation (in any type of vector)
NULLMissing Value indicator in lists
NaNNot a number
-InfNegative Infinity
InfPositive infinity

Checking/ Testing the Basic Data Types

R CommandShort 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 CommandShort 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 CoercionShort 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 OperationShort Description
x + yPerform addition between the $x$ and $y$ vector
x – yPerform subtraction between the $x$ and $y$ vector
x * yPerform multiplication between the $x$ and $y$ vector
x / yPerform division between the $x$ and $y$ vector
x ^ yPerform exponentiation, “$x$ raised to power $y$”
x %% yComputes remainder, “$x$ modulo $y$”
x %/% yPerforms Integer division, “$x$ divided by $y$”, discard the fractional part

Rounding off the Numbers

R CommandShort 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 CommandShort 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 FunctionsShort 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 FunctionsShort 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