Base R Cheat Sheet

In Base R

Base R is a programming language that is widely used for statistical computing and graphics. It is a free and open-source software that provides a wide range of tools for data analysis, manipulation, and visualization. Base R is a powerful tool for data scientists, statisticians, and researchers who need to analyze large datasets and generate high-quality graphics.

One of the key features of Base R is its ability to handle data in various formats, including CSV, Excel, and SQL databases. It also provides a wide range of functions for data manipulation, such as filtering, sorting, merging, and reshaping. Base R also includes powerful statistical functions for hypothesis testing, regression analysis, and time series analysis.

This cheat sheet will get you started! Enjoy!

Data Structures

Data StructureDescription
VectorA collection of elements of the same data type
MatrixA collection of elements arranged in a two-dimensional rectangular layout
ArrayA collection of elements arranged in a multi-dimensional rectangular layout
ListA collection of elements of different data types
Data FrameA collection of elements arranged in a two-dimensional rectangular layout, where each column can have a different data type

Data Types

Data TypeDescription
NumericNumbers with decimal points
IntegerWhole numbers
LogicalTRUE or FALSE
FactorCategorical data

Basic Operations

AssignmentAssigns a value to a variable
ArithmeticPerforms mathematical operations
ComparisonCompares two values and returns a logical value
LogicalCombines logical values using AND, OR, and NOT
SubsetExtracts a subset of a data structure
MergeCombines two data frames based on a common column

Control Structures

Control StructureDescription
if-elseExecutes a block of code if a condition is TRUE, and another block of code if it is FALSE
forExecutes a block of code a fixed number of times
whileExecutes a block of code as long as a condition is TRUE
repeatExecutes a block of code indefinitely until a break statement is encountered
switchExecutes a block of code based on the value of an expression


meanCalculates the mean of a vector
sdCalculates the standard deviation of a vector
varCalculates the variance of a vector
sumCalculates the sum of a vector
lengthCalculates the length of a vector
strsplitSplits a character string into substrings based on a delimiter


read.csvReads a CSV file into a data frame
write.csvWrites a data frame to a CSV file
read.tableReads a tabular file into a data frame
write.tableWrites a data frame to a tabular file
readLinesReads lines from a text file into a character vector
writeLinesWrites lines from a character vector to a text file


Base R Documentation