Skip to main content

Section 1.12 Key Functions & Commands

The following functions, operators, and commands are introduced for the first time in this chapter and form the foundation for working in R.
  • <- (base R) β€” Assigns values to objects for later use.
  • c() (base R) β€” Combines multiple values into a single vector.
  • : (base R) β€” Creates integer sequences (e.g., 1:10).
  • [] (base R) β€” Indexes and subsets elements from vectors or data frames.
  • $ (base R) β€” Accesses or creates columns within a data frame.
  • sqrt() (base R) β€” Computes square roots.
  • log() / log10() (base R) β€” Computes natural and base-10 logarithms.
  • round() (base R) β€” Rounds numeric values to a specified number of digits.
  • class() (base R) β€” Identifies the data type (class) of an object.
  • length() (base R) β€” Returns the number of elements in a vector.
  • factor() (base R) β€” Converts character data into categorical (factor) variables.
  • levels() (base R) β€” Displays the levels associated with a factor.
  • data.frame() (base R) β€” Combines vectors into a tabular data structure.
  • head() / tail() (base R) β€” Displays the first or last rows of a dataset.
  • str() (base R) β€” Displays the internal structure and data types of a dataset.
  • summary() (base R) β€” Produces descriptive summaries of variables in a dataset.
  • nrow() / ncol() (base R) β€” Returns the number of rows or columns in a dataset.
  • colnames() (base R) β€” Displays or modifies column names of a data frame.
  • read.csv() (base R) β€” Imports CSV files into R as data frames.
  • getwd() / setwd() (base R) β€” Gets or sets the current working directory.
  • install.packages() (base R) β€” Installs packages from CRAN.
  • library() (base R) β€” Loads an installed package into the current R session.
  • ?function_name (base R) β€” Accesses built-in help documentation for a function.