R Objects
Classes
Ways to store Objects
Naming ConventionsVectors
Numbers
Character Strings
Creating Vectors
Missing Values (NA/NaN)
NULL
Vector Name
CoercionVector Operations
Arithmetic and Logical Operations
Vector Recycling
Vector Indexing
Create Vectors
Using all() and any()
Vectorized Operation
Filtering
Filtering with subset() and which()
Testing EqualityMatrices and Arrays
Matrices
Create Matrices with dim()
Check Matrix Size
Create Matrices with bind
Index Matrices
Performing Linear Algebra
Matrix sub setting
Use apply()
apply() with user defined function
ArraysLists
Creating Lists
Attributes of a List
Access Elements in Lists
Add Elements to Lists
Remove Elements from Lists
The lapply() and sapply()
unlist()
Use Lists
Factors and Dataframes
Dataframes
Dataframes vs Lists
Creating Dataframes
General Attributes of Dataframes
Coerce in Dataframes
Access and Subsetting in Dataframes
Adding/Removing
Filtering
NA Values
Names
Factor
Factor Levels
TablesString Manipulation
Character String
Common Functions
Regular Expression
Escape Sequences
Data Input and Output
Data Management in R
Reading in Data
Writing Data to File
read.table()
Writing to a File
Resources for the More Advanced User
Data Management
Built-In Datasets
Example for data()
Reshaping Data
Removing Missing Data
Functions
Function Syntax
When to Use Functions
Example: Fahrenheit to Celsius
Call a Function
Celsius into Kelvin
Composing Functions: Fahrenheit to Kelven
Composing Functions
Naming Conventions
Variable Scope
ReferencesTesting, Error Handling
Testing
More Tips for Testing
Error HandlingDefining Defaults and Documentation
Define Defaults
Call Function with Defaults
Documentation
Formal Documentation
Control Statements
Types of Control Statements
For Loop
If Else Statement
Small Assignment on Functions with If Else
If Else & For Loop
Small Assignment on the pt.types DataframeR Objects
Debugging
Why we Debug
Debugging R Functions
Principles of Debugging
Debugging Tools in R and Rstudio
Performance Enhancement
Background
Writing Fast R Code
Vectorization
A Simple Example
Example with User Defined Function
Time Consumption
More Vectorized Functions
Simulation Speedup
Time Consumption
Growing Objects
A Few more Examples
Key Takeaways
Vectorization Demo Code
Parallel
Background
Parallel in R
When to Parallel
Simple Example
Functions with Built-In Multiple Core Support
Use mclapply()
Windows parLapply()
Parallel Demo Code