-
Description: This course introduces the R statistical software to students with minimal prior exposure to programming. The course aims to prepare students to carry out a basic data analysis and to write simple functions. The focus is on the computational model that underlies the R language with the goal of providing a foundation for further coding. Topics include (not necessarily covered in the following order):
- Data types and data structures in R (e.g. vectors, arrays, lists, data frames)
- Tools for data manipulation
- Tools for data visualization
- the REPL (read-evaluate-print loop) evaluation model
- Control flow structures (e.g. conditionals, iterations)
- Writing simple functions
- Function calls
- Argument matching
- Data input/output
- The formula language of R (time permitting)
-
Instructor: Gaston Sanchez
-
Lecture: 1 hour of lecture per week
-
Lab: 1 hour of laboratory per week
-
Assignments: biweekly HW assignments
-
Exams: one midterm exam, and final test
-
Texts and Notes:
- Breaking the Ice with R
- R Coding Basics
- Rolling Dice
- Handling Strings with R
- Tidy Hurricanes
- Prof. Sanchez's slides
-
LMS: the specific learning resources of a given semester are shared in the Learning Management Sysment (LMS) approved by Campus authorities (e.g. bCourses, Canvas)
-
Policies:
π ABOUT:
We begin with the usual review of the course policies, logistics, overall expectations, topics in a nutshell, etc. At the computational level, you'll get introduced to RStudio and R.
π READING:
- Slides
- Breaking the Ice with R
βοΈ TOPICS:
- Introduction
- About the course
- First contact with R and RStudio
π ABOUT:
You'll get introduced to Markdown and its use in dynamic computational documents (e.g. Rmd
and qmd
files).
π READING:
βοΈ TOPICS:
- Markdown
- Markdown syntax
- R Markdown (
Rmd
) files
π ABOUT:
In this week we describe data types and their implementation as vectors (the most fundamental data object in R).
π READING:
βοΈ TOPICS:
- Data Types
- atomic types (e.g. logical, integer, double, character)
- coercion
π ABOUT:
We continue describing more aspects about vectors, specifically: 1) the notion of vectorized code, 2) the recycling principle, and 3) the so-called subsetting also known as subindexing or subscripting.
π READING:
βοΈ TOPICS:
- About Vectors
- Vectorization
- Recycling principle
- Subsetting
π ABOUT:
We continue describing more atomic objects such as arrays (N-dimensional objects) and matrices (2-dimensional arrays).
π READING:
βοΈ TOPICS:
- More atomic objects
- Create simple matrices with matrix()
- Describe and give examples of matrix subsetting (subscripting, indexing)
- Explain in what sense a matrix is a 2-dimensional object
π ABOUT:
In this week, we discuss lists, which are the most generic kind of data container in R.
π READING:
βοΈ TOPICS:
- Lists
- Manipulation of lists
- Lists as one dimensional obejcts
- Subsetting lists
π ABOUT:
In this week, we discuss the basics of data frames, which are the dedicated object in R for handling tabular data sets.
π READING:
βοΈ TOPICS:
- Data Frames
- manipulation data frames (the "classic" way)
- data frames as lists
- data frames as two dimensional objects
π ABOUT:
You donβt need to be an expert programmer to use R, but learning more about programming allows you to automate common tasks, and solve new problems with greater ease. We'll discuss how to write basic functions, and the notion of R expressions.
π READING:
βοΈ TOPICS:
- Functions
- Main parts of a function (i.e. anatomy of a function)
- Examples for creating a function
- Concepts of an R compound expression
π ABOUT:
If-else statements are one of the fundamental programming structures available in all programming languages. Simply put, an if-else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed.
π READING:
βοΈ TOPICS:
- If-else statements
- Anatomy of an
if-else
statement - Use of an
if-else
statements when writing functions to decide what code to execute
- Anatomy of an
π ABOUT:
In addition to writing functions to reduce duplication in your code, you also need to learn about iteration, which helps you when you need to do the same operation several times. Namely, we review control flow structures such as for loops, while loops, repeat loops, and the apply family functions.
π READING:
βοΈ TOPICS:
- Loops
- Write for loops to repeat the same operation a given number of times
- Write while loops to repeat the same operation an unknown number of time
π ABOUT:
Why should you learn about character string manipulation and working with text data? Well, because a considerable amount of information and data is precisely in the form of text. And sooner or later you will have to deal with some kind of string manipulation in most programming activities.
π READING:
- Slides
βοΈ TOPICS:
- Basic string processing
- set of functions to perform basic manipulation of character strings.
π ABOUT:
A considerable amount of information and data is in the form of text. To unleash the power of string manipulation, you need to learn about Regular Expressions (or regex). Namely, regular expressions allow you to describe a certain amount of text called "patterns". We'll describe the basic concepts of regex and the common operations to match text patterns.
π READING:
- Slides
βοΈ TOPICS:
- Basic regex
- literal characters
- wildcard metacharacter
- character sets
π ABOUT:
A considerable amount of information and data is in the form of text. To unleash the power of string manipulation, you need to learn about Regular Expressions (or regex). Namely, regular expressions allow you to describe a certain amount of text called "patterns". We'll describe the basic concepts of regex and the common operations to match text patterns.
π READING:
- Slides
βοΈ TOPICS:
- More regex
- character ranges
- posix classes
- anchors
- modifiers and quantifiers