rguides

Reference

Base Functions

Core R functions available in base R.

  1. abs()

    Compute absolute values for numeric vectors. Converts negative numbers to positive, leaving zeros unchanged. Essential for distance and error calculations.

  2. 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.

  3. 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.

  4. cat()

    Concatenate and print objects to a file or connection, with minimal formatting.

  5. ceiling()

    Round numeric values up to the nearest integer in R.

  6. 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.

  7. colnames()

    Get or set the column names of a matrix, data frame, or other R object.

  8. cos()

    Compute the trigonometric cosine of values in R.

  9. cummax()

    Compute the cumulative maximum of a vector in R.

  10. cummin()

    Compute the cumulative minimum of a vector in R.

  11. cumprod()

    Compute the cumulative product of a vector in R.

  12. cumsum()

    Compute the cumulative sum of a vector in R.

  13. diff()

    Calculate lagged differences between elements in a vector, useful for detecting changes, trends, and rate of change in sequential data.

  14. dim()

    Get or set the dimensions of an object (matrix, data frame, array).

  15. 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.

  16. duplicated()

    Identify duplicate elements in R objects.

  17. exp()

    Compute the exponential of values in R (e^x).

  18. expm1()

    Compute exp(x) - 1 for small values of x, providing numerical stability.

  19. filter

    Apply linear filters to time series — moving averages via convolution, autoregressive filters via recursion, with alignment and circular wrapping control.

  20. find

    Locate which environment in the search path contains an object of a given name. Returns environment names or search path positions.

  21. floor()

    Round numeric values down to the nearest integer in R.

  22. head()

    Return the first or last parts of a vector, matrix, table, data frame or function.

  23. ifelse()

    Transform elements based on a condition, returning one value if TRUE and another if FALSE.

  24. intersect()

    Return the intersection of two vectors — elements common to both vectors.

  25. is.na()

    Test for missing values (NA) in R objects.

  26. is.nan()

    Test for NaN (Not a Number) values in R.

  27. is.null()

    Test whether an object is NULL in R.

  28. is.numeric()

    Test whether an object has numeric type in R.

  29. lapply()

    Apply a function to each element of a list or vector, returning a list.

  30. length()

    Get or set the length of a vector, list, or other R object in R

  31. log()

    Compute the natural logarithm (base e) of values in R.

  32. log10()

    Compute the logarithm of values in base 10.

  33. log1p()

    Compute the natural logarithm of (1 + x) for small values of x, providing numerical stability.

  34. log2()

    Compute the logarithm of values in base 2.

  35. 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.

  36. mapply()

    Apply a function to multiple arguments in parallel — first elements together, then second elements, and so on.

  37. match()

    Find element positions in a vector, returning indices of first matches.

  38. max()

    Find the maximum value in a vector or across multiple arguments.

  39. mean()

    Compute the arithmetic mean of a numeric vector, with optional trimming and NA handling.

  40. message

    R base function to output diagnostic messages to stderr without halting execution.

  41. min()

    Find the minimum value in a vector or across multiple arguments.

  42. ncol()

    Get the number of columns in a matrix, array, or data frame. Returns NULL for vectors.

  43. 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.

  44. nrow()

    Get the number of rows in a matrix, array, or data frame. Returns NULL for vectors.

  45. on.exit

    Register an expression to be evaluated when the enclosing function exits.

  46. order()

    Return the permutation that sorts a vector, or sort multiple vectors by one.

  47. paste()

    Concatenate strings with a separator, converting vectors to character and optionally collapsing into a single string.

  48. paste0()

    Concatenate strings end-to-end without inserting separators between elements.

  49. position

    Find positional indices of values in R vectors — which.max for maximum position, rank for order-based ranks, and order for sorting indices.

  50. print()

    Print objects to the console or output connection. Generic function with methods for different object types.

  51. range()

    Returns the minimum and maximum values of a numeric vector, or the smallest and largest strings alphabetically.

  52. readline()

    Read a line from the console or a connection for interactive user input in R scripts.

  53. Reduce

    Apply a binary function cumulatively to reduce a vector to a single value. Supports initial values, right-to-left reduction, and accumulate mode.

  54. rep()

    Replicate elements of a vector or list a specified number of times, creating repeated sequences.

  55. rm()

    Remove objects from the specified environment by name, freeing memory and reducing namespace clutter.

  56. round()

    Round numeric values to a specified number of decimal places.

  57. rownames()

    Get or set the row names of a matrix, data frame, or other R object.

  58. sample()

    Sample random elements from a vector or take a random subset of elements for simulation, testing, or resampling.

  59. sapply()

    Apply a function to each element of a vector or list, simplifying the result to a vector or matrix when possible.

  60. sd()

    Compute the standard deviation of numeric vectors in R.

  61. seq()

    Generate regular sequences of numbers with customizable start, end, length, and increment.

  62. setdiff()

    Return elements in the first vector but not in the second — set difference operation.

  63. sin()

    Compute the trigonometric sine of values in R.

  64. sort()

    Sort a vector into ascending or descending order. Returns the input vector with elements arranged from smallest to largest.

  65. sprintf()

    Format strings using C-style sprintf formatting to insert values into text templates.

  66. sqrt()

    Compute the square root of values in R.

  67. stop

    Signal an error and halt execution in R with stop(), including custom messages, call control, and condition objects.

  68. substr()

    Extract or replace substrings in a character vector

  69. sum()

    Calculate the sum of all elements in a vector or matrix, with optional handling of missing values.

  70. switch()

    Select one alternative from a list based on an integer index or character string match. Returns the selected element or NULL when no match exists.

  71. Sys.sleep

    Pause R execution for a specified number of seconds. Simple, side-effect-only delay for loops, retries, and rate-limiting.

  72. Sys.time

    Get the current date and time as a POSIXct object representing seconds since the Unix epoch.

  73. system

    Execute system commands from R. Runs shell commands and returns exit status or captured output.

  74. system2

    Execute external commands from R, capturing output and exit status

  75. table()

    Create contingency tables showing frequency counts for categorical variables, cross-tabulating one or more factors into a table of counts.

  76. tan()

    Compute the trigonometric tangent of values in R.

  77. tapply()

    Apply a function to each level of a factor or group in a vector, creating grouped summaries.

  78. trunc()

    Truncate numeric values toward zero in R.

  79. tryCatch

    Catch and handle R conditions including errors, warnings, and messages with tryCatch().

  80. union()

    Return the union of two vectors — all unique elements from both vectors.

  81. unique()

    Extract unique values from a vector or remove duplicated rows in R objects.

  82. vapply()

    Apply a function to each element of a vector or list, returning a vector, matrix, or array with enforced type safety via FUN.VALUE.

  83. var()

    Compute the variance of numeric vectors in R.

  84. warning

    Signal a warning in R with warning(), controlling call display, warn levels, suppression, and custom handlers.

  85. which.max / which.min()

    Find the index of the minimum or maximum value in a vector, essential for locating extreme values in R.

  86. which()

    Return the indices of elements that satisfy a logical condition, enabling efficient filtering and subsetting in R.

  87. withCallingHandlers()

    Register calling handlers for warnings, messages, and errors in R while preserving access to the call stack.

  88. writeLines()

    Write text lines to a file or connection in R, with control over line endings and encoding.