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 Structure
Description
Vector
A collection of elements of the same data type
Matrix
A collection of elements arranged in a two-dimensional rectangular layout
Array
A collection of elements arranged in a multi-dimensional rectangular layout
List
A collection of elements of different data types
Data Frame
A collection of elements arranged in a two-dimensional rectangular layout, where each column can have a different data type
Data Types
Data Type
Description
Numeric
Numbers with decimal points
Integer
Whole numbers
Logical
TRUE or FALSE
Character
Text
Factor
Categorical data
Basic Operations
Operation
Description
Assignment
Assigns a value to a variable
Arithmetic
Performs mathematical operations
Comparison
Compares two values and returns a logical value
Logical
Combines logical values using AND, OR, and NOT
Subset
Extracts a subset of a data structure
Merge
Combines two data frames based on a common column
Control Structures
Control Structure
Description
if-else
Executes a block of code if a condition is TRUE, and another block of code if it is FALSE
for
Executes a block of code a fixed number of times
while
Executes a block of code as long as a condition is TRUE
repeat
Executes a block of code indefinitely until a break statement is encountered
switch
Executes a block of code based on the value of an expression
Functions
Function
Description
mean
Calculates the mean of a vector
sd
Calculates the standard deviation of a vector
var
Calculates the variance of a vector
sum
Calculates the sum of a vector
length
Calculates the length of a vector
strsplit
Splits a character string into substrings based on a delimiter
Input/Output
Function
Description
read.csv
Reads a CSV file into a data frame
write.csv
Writes a data frame to a CSV file
read.table
Reads a tabular file into a data frame
write.table
Writes a data frame to a tabular file
readLines
Reads lines from a text file into a character vector
writeLines
Writes lines from a character vector to a text file