R @ Ewha 2020
1
Week1: Introduction to R
1.1
Reading for this lecture
1.2
Two ways to read lecture notes
1.3
Welcome
1.4
Why R?
1.5
R vs Python
1.6
Let’s install R to your local computer
1.7
Let’s install RStudio to your local computer
1.8
Three ways you can use R in this course
1.9
Useful R resources
1.10
R Packages
1.11
Base R vs Tidyverse
1.12
R script file vs R markdown file
1.13
R markdown
1.14
Let’s get familiar with RStudio
1.15
Things that you can do with R and RStudio
1.16
Homework (this HW will not be graded !!)
1.17
Comments of Week1 lecture
2
Week2: Data Visualization I
2.1
What is
ggplot2
?
2.2
Graphical components
2.3
ggplot2 syntax
2.4
Learning objectives of this lecture
2.5
Installing and laoding ggplot2
2.6
Useful resources for learning ggplot2
2.7
Graphical components of ggplot2
2.7.1
Data
2.7.2
Geometric objects (
geoms
)
2.7.3
Aesthetic mappings
2.7.4
Scales
2.7.5
Statistical transformations
2.7.6
Position adjustments
2.7.7
A faceting
2.7.8
Grouping
2.8
Themes
2.9
Saving a ggplot
2.10
Frequently used plots
2.10.1
qplot()
2.10.2
Scatterplots
2.10.3
Histogram
2.10.4
Density plots
2.10.5
Barplots
2.10.6
Boxplots
2.10.7
The
corrplot
Package
2.11
Homework (this HW will not be graded !!)
3
Week3: Data Visualization II
3.1
The Review of Key Concepts in ggplot2
3.2
Annotations
3.2.1
Adding Text Annotations
3.2.2
Adding Lines
3.3
Axes
3.3.1
Swapping X- and Y-Axes
3.3.2
Setting the Position of Tick Marks
3.3.3
Changing the Text of Tick Labels
3.3.4
Changing the Appearance of Tick Labels
3.4
Using Colors in Plots
3.4.1
Setting and Mapping the Colors of Objects
3.4.2
Using a Different Palette for a Discrete Variable
3.4.3
Using a Manually Defined Palette for a Discrete Variable
3.4.4
Using a Manuallly Defined Palette for a Continuous Variable
3.5
Legends
3.6
Exercise
3.6.1
Exercise 3-1
3.6.2
Exercise 3-2
4
Week 4 : R markdown
4.1
What is R markdown documents?
4.2
Wonderful resources for R markdown
4.3
RStudio Projects
4.4
Publish your R markdown Documents
5
Week 5 : Base R
5.1
Objects, variables, and assignment operator
5.2
Functions
5.2.1
An Example of Functions
5.2.2
User-Defined Functions
5.2.3
Exercise on functions
5.2.4
Some Comments on Functions
5.3
Operators
5.4
Data Structure
5.5
Vectors
5.5.1
Vectors Come in Two Flavours
5.5.2
A Vector Has Three Properties
5.5.3
Attributes
5.5.4
Type Coercion (Conversion)
5.5.5
NA represents missing
5.5.6
Generate a vector
5.5.7
Indexing or subsetting a Vector
5.5.8
Arrange a vector
5.5.9
Vectorization of Functions
5.5.10
Some more functions
5.5.11
Generating Sequences
5.5.12
Exercise on vectors
5.6
Factors
5.6.1
What is a factor?
5.6.2
Creating a factor
5.6.3
unordered vs ordered factor
5.6.4
Why factors?
5.6.5
Some more comments
5.6.6
Exercise on factors
5.7
Lists
5.7.1
What is a list?
5.7.2
Creating a list
5.7.3
Why lists?
5.7.4
Subsetting a List
5.7.5
Exercise on lists
5.7.6
Data frames
5.7.7
The apply family of functions
5.7.8
Exercise
5.7.9
More resources
5.8
Matrices and Arrays
5.8.1
Subsetting a Matrix and Array
5.8.2
Exercise
5.8.3
Combine Matrices by Columns or Rows
5.8.4
Names of the Columns and Rows of Matrices
5.9
Data Frames
5.10
Control Flow
5.10.1
if-else
5.10.2
for
5.11
Further reading
6
Base R Practice Problems
7
Base R Quiz
7.1
Instruction on the quiz
7.2
Dataset:
bfi
is a dataset in the
psych
package containing 25 personality self report items taken from the International Personality Item Pool. In the dataset,
7.3
Quiz problem 1
7.4
Quiz problem 2
7.5
Quiz problem 3
7.6
Quiz problem 4
7.7
Quiz problem 5
8
Week 7 : The dplyr package
8.1
What is dplyr?
8.2
Cheat Sheet
8.3
Tibbles
8.4
Select columns with
select()
8.5
Filter rows with
filter()
8.6
Add new variables with
mutate()
8.7
Arrange rows with
arrange()
8.8
Grouped summaries with summarize()
8.9
The pipe operator %>%
8.10
Style Guide
8.11
Grouped summaries with summarize() (continue)
8.12
Mutating joins
9
dplyr practice
9.1
starwars data
9.2
data sets in the ds4psy package
10
dplyr quiz
11
Week 8 : The tidyr package
11.1
What is tidyr?
11.2
An example
11.3
pivot_longer()
11.4
pivot_wider()
11.5
separate()
11.6
unite()
R @ Ewha 2020
10
dplyr quiz