Day 1: Introduction to R
Learning Objectives
- to be able to use the basic features of RStudio.
- to understand different types of R-base data structures and how to create and manipulate them.
- understand how to do Matrix/Linear Algebra in R.
- to be able to install and load R packages.
- to be able to load and save data in R.
Preparation
If you are entirely new to R and RStudio, the following sections from the book “R for Data Science” might be helpful to read before the class. Each section is short. Also, don’t worry about the code written in the book.
Section 6: Workflow scripts and projects
- We’ll use RStudio projects instead of setting working directory manually. Section 6.2.3: RStudio projects explains RStudio projects.
Lecture Slides
Click here for Lecture 0’s slides.
Click here for Lecture 1’s slides.
Exercise problems: Exercise problems for Lecture 1. Solution is attached.
Quick view of the Lecture 1’s slides:
Supplementary Materials
You can find a lot of features of R studio from here.
rio Package: Import, Export, and Convert Data Files
import()andexport()function from theriopackage can be used to import and export data in various formats.
Faster matrix operations in R
By default, R uses two libraries for common mathematical operations: Basic Linear Algebra Subprograms (BLAS) and LAPACK (Linear Algebra Package). For MAC users, instead of the BLAS library that comes with R, you can use Apple’s vecLib (libBLAS.dylib), which is optimized for Apple to perform computations on large vectors. I don’t know if this works on your machine (especially for Windows). But you can try it to speed up R! The process is not complicated. Just follow the instructions in the link below.
Accelerating R by Dr. Christopher D. Higgins
Even faster matrix math in R on macOS with M1 by Mikhail Popov