Base Functions
Core R functions available in base R.
abs()
Compute absolute values for numeric vectors. Converts negative numbers to positive, leaving zeros unchanged. Essential for distance and error calculations.
abs(x) 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.
apply(X, MARGIN, FUN, ...) c()
Combine values into a vector or list. This is the most fundamental function in R for creating vectors, used extensively in data manipulation and programming.
c(..., recursive = FALSE, USE.NAMES = TRUE) cat()
Concatenate and print objects to a file or connection, with minimal formatting.
cat(... , file = "", sep = " ", fill = FALSE, labels = NULL, append = FALSE) ceiling()
Round numeric values up to the nearest integer in R.
ceiling(x) 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.
class(x) colnames()
Get or set the column names of a matrix, data frame, or other R object.
colnames(x) <- value cos()
Compute the trigonometric cosine of values in R.
cos(x) cummax()
Compute the cumulative maximum of a vector in R.
cummax(x) cummin()
Compute the cumulative minimum of a vector in R.
cummin(x) cumprod()
Compute the cumulative product of a vector in R.
cumprod(x) cumsum()
Compute the cumulative sum of a vector in R.
cumsum(x) diff()
Calculate lagged differences between elements in a vector, useful for detecting changes, trends, and rate of change in sequential data.
diff(x, lag = 1, differences = 1) dim()
Get or set the dimensions of an object (matrix, data frame, array).
dim(x) duplicated()
Identify duplicate elements in R objects.
duplicated(x, incomparables = FALSE, MARGIN = 1, fromLast = FALSE, ...) exp()
Compute the exponential of values in R (e^x).
exp(x) expm1()
Compute exp(x) - 1 for small values of x, providing numerical stability.
expm1(x) floor()
Round numeric values down to the nearest integer in R.
floor(x) head()
Return the first or last parts of a vector, matrix, table, data frame or function.
head(x, n = 6L, ...) ifelse()
Transform elements based on a condition, returning one value if TRUE and another if FALSE.
ifelse(test, yes, no) intersect()
Return the intersection of two vectors — elements common to both vectors.
intersect(x, y) is.na()
Test for missing values (NA) in R objects.
is.na(x) is.nan()
Test for NaN (Not a Number) values in R.
is.nan(x) is.null()
Test whether an object is NULL in R.
is.null(x) is.numeric()
Test whether an object has numeric type in R.
is.numeric(x) lapply()
Apply a function to each element of a list or vector, returning a list.
lapply(X, FUN, ...) length()
Get or set the length of a vector, list, or other R object in R
length(x) log()
Compute the natural logarithm (base e) of values in R.
log(x, base = exp(1)) log10()
Compute the logarithm of values in base 10.
log10(x) log1p()
Compute the natural logarithm of (1 + x) for small values of x, providing numerical stability.
log1p(x) log2()
Compute the logarithm of values in base 2.
log2(x) match()
Find element positions in a vector, returning indices of first matches.
match(x, table, nomatch = NA_integer_, incomparables = FALSE) max()
Find the maximum value in a vector or across multiple arguments.
max(..., na.rm = FALSE, na.last = TRUE, type = c("ordinary", "ordered"))
mean()
Compute the arithmetic mean of a numeric vector, with optional trimming and NA handling.
mean(x, trim = 0, na.rm = FALSE, ...) min()
Find the minimum value in a vector or across multiple arguments.
min(..., na.rm = FALSE, na.last = TRUE, type = c("ordinary", "ordered"))
ncol()
Get the number of columns in a matrix, array, or data frame. Returns NULL for vectors.
ncol(x) nrow()
Get the number of rows in a matrix, array, or data frame. Returns NULL for vectors.
nrow(x) on.exit
Register an expression to be evaluated when the enclosing function exits.
order()
Return the permutation that sorts a vector, or sort multiple vectors by one.
order(..., na.last = TRUE, decreasing = FALSE) paste()
Concatenate strings with a separator, converting vectors to character and optionally collapsing into a single string.
paste(..., sep = " ", collapse = NULL, recycle0 = FALSE) paste0()
Concatenate strings end-to-end without inserting separators between elements.
paste0(..., collapse = NULL) print()
Print objects to the console or output connection. Generic function with methods for different object types.
print(x, ...) range()
Returns the minimum and maximum values of a numeric vector, or the smallest and largest strings alphabetically.
range(..., na.rm = FALSE) readline()
Read a line from the console or a connection for interactive user input in R scripts.
readline(prompt = NULL) rep()
Replicate elements of a vector or list a specified number of times, creating repeated sequences.
rep(x, times = 1, length.out = NA, each = 1) rm()
Remove objects from the specified environment by name, freeing memory and reducing namespace clutter.
rm(..., list = character(), envir = as.environment(pos)) round()
Round numeric values to a specified number of decimal places.
round(x, digits = 0) rownames()
Get or set the row names of a matrix, data frame, or other R object.
rownames(x) <- value sample()
Sample random elements from a vector or take a random subset of elements for simulation, testing, or resampling.
sample(x, size, replace = FALSE, prob = NULL) sapply()
Apply a function to each element of a vector or list, simplifying the result to a vector or matrix when possible.
sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE) sd()
Compute the standard deviation of numeric vectors in R.
sd(x, na.rm = FALSE) seq()
Generate regular sequences of numbers with customizable start, end, length, and increment.
seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)), length.out = NULL, along.with = NULL) setdiff()
Return elements in the first vector but not in the second — set difference operation.
setdiff(x, y) sin()
Compute the trigonometric sine of values in R.
sin(x) sort()
Sort a vector into ascending or descending order. Returns the input vector with elements arranged from smallest to largest.
sort(x, decreasing = FALSE, na.last = NA) sprintf()
Format strings using C-style sprintf formatting to insert values into text templates.
sprintf(fmt, ...) sqrt()
Compute the square root of values in R.
sqrt(x) substr()
Extract or replace substrings in a character vector
substr(x, start, stop) sum()
Calculate the sum of all elements in a vector or matrix, with optional handling of missing values.
sum(..., na.rm = FALSE) Sys.sleep
Pause R execution for a specified number of seconds. Simple, side-effect-only delay for loops, retries, and rate-limiting.
Sys.sleep(time) system2
Execute external commands from R, capturing output and exit status
system2(command, args = character(), stdout = "", stderr = "", stdin = "", input = NULL, env = character(), wait = TRUE, timeout = 0) table()
Create contingency tables showing frequency counts for categorical variables, cross-tabulating one or more factors into a table of counts.
table(..., exclude = NA, useNA = c("no", "ifany", "always")) tan()
Compute the trigonometric tangent of values in R.
tan(x) tapply()
Apply a function to each level of a factor or group in a vector, creating grouped summaries.
tapply(X, INDEX, FUN = NULL, ..., default = NA, simplify = TRUE) trunc()
Truncate numeric values toward zero in R.
trunc(x) union()
Return the union of two vectors — all unique elements from both vectors.
union(x, y) unique()
Extract unique values from a vector or remove duplicated rows in R objects.
unique(x, incomparables = FALSE, MARGIN = 1, fromLast = FALSE, ...) var()
Compute the variance of numeric vectors in R.
var(x, y = NULL, na.rm = FALSE, use) which.max / which.min()
Find the index of the minimum or maximum value in a vector, essential for locating extreme values in R.
which.min(x) / which.max(x) which()
Return the indices of elements that satisfy a logical condition, enabling efficient filtering and subsetting in R.
which(x, arr.ind = FALSE, useNames = TRUE) withCallingHandlers()
Register calling handlers for warnings, messages, and errors in R while preserving access to the call stack.
withCallingHandlers(expr, ..., finally = NULL)