The abs() function computes absolute values for numeric vectors in R, converting negatives to positives. Essential for distance and error calculations.
Reference
Base Functions
Core R functions available in base R.
- abs()
- aggregate()
aggregate() splits data into subsets by one or more grouping variables and applies a summary function to each, returning a data frame of per-subset results.
- apply()
Apply a function over the margins of an array or matrix in R. A core base R function for iterative operations on rectangular data structures.
- by()
by() applies a function to subsets of a data frame split by one or more factors — the data-frame wrapper for tapply().
- c()
The c() function combines values into a single vector or list in R, the most fundamental way to create vectors from individual elements in everyday programming.
- cat()
The cat() function concatenates and prints R objects to the console or a file with minimal formatting and full control over separators.
- ceiling()
The ceiling() function rounds numeric values up to the nearest integer in R (toward positive infinity), useful for pagination, batching, and safe upper bounds.
- class()
Get or set the class attribute of an R object. Returns the class vector for an object, or can be used to assign a new class.
- colnames()
colnames() gets or sets the column names of a matrix, data frame, or array-like R object, used to inspect and rename columns in tabular data.
- connection
R connection objects: file, url, gzfile, pipe, socket, and the open, close, and isOpen methods that operate on them.
- cos()
cos() computes the trigonometric cosine of numeric values in R, operating element-wise on vectors and accepting angles in radians.
- cummax()
The cummax() function computes the cumulative maximum of a vector in R, returning the running maximum at each position from left to right.
- cummin()
The cummin() function computes the cumulative minimum of a vector in R. It returns the running minimum, each position holding the smallest value seen so far.
- cumprod()
cumprod() computes the cumulative product of a vector in R, useful for compound growth and geometric sequences where each step builds on the previous product.
- cumsum()
The cumsum() function computes the cumulative sum of a vector in R, the simplest way to build running totals in reporting, finance, and time-series analysis.
- diff()
diff() computes lagged differences between successive elements of a numeric vector, useful for detecting changes, trends, and rate of change in sequential data.
- dim()
Get or set the dimensions of an object (matrix, data frame, array). dim() returns the dimensions of an array, matrix, or data frame.
- do.call
Call a function with arguments from a list or environment. Build a call expression with call() first, then evaluate it with do.call.
- duplicated()
The duplicated() function identifies duplicate elements in R objects, returning a logical vector indicating which elements (or rows) are duplicates.
- exp()
exp() computes the exponential of values in R (e^x) and is one of the most frequently called math functions in statistical computing.
- expm1()
The expm1() function computes exp(x) - 1 for small values of x with full precision, avoiding the cancellation that occurs when x is near zero.
- file()
file() opens a file or URL connection in R, returning a connection object for readLines(), writeLines(), readBin(), and other I/O functions.
- filter
Apply linear filters to time series, moving averages via convolution, autoregressive filters via recursion, with alignment and circular wrapping control.
- find
Use find() to locate which environment in the search path contains an object of a given name. Returns environment names or search path positions.
- floor()
Use floor() to round numeric values down to the nearest integer in R. This pattern is commonly used for creating histogram bins or demographic categories.
- head()
head() returns the first parts of a vector, matrix, table, data frame or function in R, complementing tail() which returns the last n elements.
- ifelse()
Transform elements based on a condition, returning one value if TRUE and another if FALSE. The ifelse() function is R's vectorized conditional operator.
- intersect()
intersect() returns the elements that appear in both of two vectors in R, useful for comparing IDs, categories, or labels shared between datasets.
- is.na()
is.na() tests whether elements in an R object are missing values (NA), returning a logical vector of the same length as the input.
- is.nan()
The is.nan() function tests whether elements in an R object are NaN (Not a Number), identifying undefined results from operations like 0/0 or sqrt(-1).
- is.null()
`is.null()` tests whether an R object is NULL — the complete absence of a value, distinct from NA which represents unknown but present data.
- is.numeric()
The is.numeric() function tests whether an R object has numeric type, returning TRUE for both integer and double (floating-point) values.
- lapply()
The lapply() function applies a function to each element of a list or vector, returning a list. It always returns a list of the same length as the input.
- length()
Get or set the length of a vector, list, or other R object in R. It is one of the most frequently used functions in R for determining the size of objects.
- log()
The log() function computes the natural logarithm (base e) of a number in R, with an optional base argument for logarithms in any base.
- log10()
`log10()` computes the base-10 logarithm of a numeric vector, returning the power to which 10 must be raised to produce each value.
- log1p()
log1p() computes the natural logarithm of (1 + x) with high numerical stability for small values of x. It is more accurate than log(1 + x) when x is very small.
- log2()
log2() computes the base-2 logarithm of numeric values. It is vectorized, handles NA and infinite values, and is commonly used in information theory.
- Map
Apply a function to multiple arguments in R with Map. This base function wraps mapply with SIMPLIFY=FALSE, always returning a list of results.
- mapply()
mapply() applies a function to multiple arguments in parallel, processing matching elements together and recycling shorter vectors automatically.
- match()
Find element positions in a vector, returning indices of first matches. returns the position of the first match between elements of in .
- max()
The max() function returns the maximum value across its arguments in R, with na.rm for handling missing values and pmax() for element-wise comparisons.
- mean()
Compute the arithmetic mean of a numeric vector, with optional trimming and NA handling. computes the arithmetic mean.
- merge
Merge two data frames by common columns or row names with R's base merge(). Covers by, all.x, all.y, suffixes, and NA matching.
- message
R base function to output diagnostic messages to stderr without halting execution. sends diagnostic output to the connection.
- min()
Find the minimum value in a vector or across multiple arguments with the min() function. Handles NA values and returns the smallest element.
- ncol()
Get the number of columns in a matrix, array, or data frame with the ncol() function. Returns NULL for atomic vectors since they lack a column dimension.
- negate
Flip a predicate function with purrr negate, TRUE becomes FALSE, FALSE becomes TRUE. Use to discard what you would keep, or keep what you would discard.
- nrow()
The nrow() function gets the number of rows in a matrix, array, or data frame. It returns NULL for atomic vectors since vectors have no dimensions.
- on.exit
on.exit() registers cleanup expressions that run when a function exits, handling resource teardown whether the function returns normally or encounters an error.
- order()
Use order() to return the permutation that sorts a vector, or sort multiple vectors by one. Returns the indices that would sort a vector or set of vectors.
- paste()
The paste() function concatenates strings with a separator, converting vectors to character and optionally collapsing the result into a single string.
- paste0()
paste0() concatenates strings end-to-end without separators. Equivalent to paste(..., sep = ""), it is the fastest way to join strings in base R.
- position
Find positional indices and ranks in R — which.max for maximum position, which.min for minimum, rank for order-based ranks, and order for sorting indices.
- print()
Print objects to the console or output connection. Generic function with methods for different object types. is generic, it dispatches to , , etc.
- range()
range() returns the min and max of a vector as a length-2 vector, or the smallest and largest strings alphabetically for character data.
- readline()
`readline()` reads a line from the terminal in interactive R sessions, pausing execution until the user types a response and presses Enter.
- readLines()
readLines() reads text lines from a file or connection in R, returning each line as an element of a character vector.
- Reduce
Apply a binary function cumulatively to reduce a vector to a single value. Supports initial values, right-to-left reduction, and accumulate mode.
- regexpr
regexpr() returns the position and length of the first regex match in each element of a character vector in R.
- rep()
`rep()` replicates vector elements with `times` for whole-vector repetition or `each` for per-element duplication, for building patterns and test data.
- reshape()
Convert data between wide and long format with the base R reshape() function from the stats package: arguments, examples, gotchas.
- rm()
`rm()` removes objects from the specified R environment by name, freeing memory and reducing namespace clutter.
- round()
Round numeric values to a specified number of decimal places. The round() function rounds numeric values to the specified number of decimal places.
- rownames()
rownames() gets or sets row names on matrices and data frames in R, enabling row-by-name access. It is the row equivalent of colnames().
- sample()
Sample random elements from a vector or take a random subset of elements for simulation, testing, or resampling.
- sapply()
The sapply() function applies a function to each element of a vector or list, simplifying the result to a vector or matrix when possible.
- scan
Read data values from a file, connection, or inline string into an R vector or list using scan(), with full control over separators, NA strings, and comments.
- sd()
`sd()` computes the sample standard deviation of a numeric vector using Bessel's correction (n-1 denominator) for unbiased population estimation.
- seq()
seq() generates regular sequences of numbers with customizable start, end, length, and increment for looping, indexing, and creating test data.
- setdiff()
The setdiff() function returns elements in the first vector but not in the second, performing an asymmetric set difference operation on R vectors.
- sin()
sin() computes the trigonometric sine of numeric values in R. It operates element-wise on vectors and accepts angles in radians.
- sort()
Sort a vector into ascending or descending order. Returns the input vector with elements arranged from smallest to largest.
- sprintf()
Format strings using C-style sprintf formatting to insert values into text templates. sprintf() formats strings using C-style format specifiers.
- sqrt()
sqrt() computes the square root of numeric values in R. It operates element-wise on vectors and returns NaN for negative inputs.
- stop
Signal an error and halt execution in R with stop(), including custom messages, call control, and condition objects.
- subset
Filter rows and pick columns from vectors, matrices, or data frames in base R with subset(). Learn syntax, NA handling, and when to reach for dplyr instead.
- substr()
The substr() function extracts or replaces substrings by position in R. Covers 1-indexed extraction, in-place assignment, and out-of-bounds behavior.
- sum()
Calculate the sum of all elements in a vector or matrix, with optional handling of missing values. adds all elements of its input vectors.
- switch()
switch() selects one alternative from a list based on an integer index or character string match. Returns the selected element or NULL when no match exists.
- Sys.sleep
The Sys.sleep function pauses R execution for a specified number of seconds — a simple, side-effect-only delay for loops, retries, and rate-limiting.
- Sys.time
sys.time() returns the current time as a POSIXct object. Use it to timestamp computations and measure elapsed time in R.
- system
Execute system commands from R. Runs shell commands and returns exit status or captured output. It is a base R function available on all platforms.
- system2
`system2()` executes external commands from R, capturing output and exit status with full control over input and output streams.
- table()
Create contingency tables showing frequency counts for categorical variables, cross-tabulating one or more factors into a table of counts.
- tan()
The tan() function computes the trigonometric tangent of numeric values in R, operating element-wise on vectors and accepting angles in radians.
- tapply()
tapply() applies a function to subsets of a vector grouped by a factor, returning an array of results — the base R equivalent of grouped summarisation.
- trunc()
The trunc() function truncates numeric values toward zero in R, removing the fractional part from each element of a numeric vector.
- tryCatch
Catch and handle R conditions including errors, warnings, and messages with tryCatch(). The function signature is: - is the expression to evaluate.
- union()
Return the union of two vectors, all unique elements from both vectors. The function returns all unique elements that appear in either of two vectors.
- unique()
Extract unique values from a vector or remove duplicated rows in R objects. returns a vector, data frame, or array with duplicate elements removed.
- vapply()
vapply() applies a function to each element of a vector or list with enforced type safety via FUN.VALUE, returning a vector, matrix, or array.
- var()
var() calculates the sample variance of a numeric vector using Bessel's correction. It also accepts a matrix to compute the variance-covariance matrix.
- warning
Signal a warning in R with warning(), controlling call display, warn levels, suppression, and custom handlers.
- which.max / which.min()
`which.max()` and `which.min()` find the index of the minimum or maximum value in a vector, essential for locating extreme values in R.
- which()
The which() function returns the indices of elements that satisfy a logical condition, enabling efficient filtering and subsetting in R.
- with
Evaluate an R expression in a local environment built from a data frame, list, or environment, so columns are reachable by short name. Pairs with `within()`.
- withCallingHandlers()
withCallingHandlers() registers calling handlers for warnings, messages, errors in R while preserving call-stack access. Returns the expression result.
- within
Return a copy of a data frame or list with columns or elements added, modified, or removed by an expression. `within()` is the write counterpart of `with()`.
- writeLines()
The writeLines() function writes text lines to a file or connection in R, with control over line endings and encoding.