Intro to R
Preface
Main references
Version history
Contributor list
Video tutorials
License
1
R and RStudio set up
1.1
Instructions
1.2
Learning Objectives
1.3
What is R?
1.4
What is RStudio?
1.5
Download and Install R
1.6
Download and Install RStudio
1.7
RStudio Basics
1.8
Summary and Takeaways
2
Introduction to R
2.1
Instructions
2.2
Learning Objectives
2.3
Set Up Basics
2.3.1
Working Directory
2.3.2
Installing and Attaching Packages
2.4
Arithmetic Operators
Try it yourself 2.1
2.5
Logical Operators
Try it yourself 2.2
2.6
Most Common Data Types In R
2.6.1
Strings
2.6.2
Vectors
Try it yourself 2.3
Try it yourself 2.4
2.6.3
Lists
2.6.4
Dataframe
Try it yourself 2.5
2.7
Exploring a Dataset
Try it yourself 2.6
2.7.1
Dimensions
2.7.2
Structure
2.7.3
Class
Try it yourself 2.7
2.7.4
Length
Try it yourself 2.8
2.7.5
Head and Tail
2.7.6
Mathematical Functions in R
Try it yourself 2.9
2.8
Writing a New Function In R
2.9
For Loops
2.10
Help Within and Outside Of R
2.10.1
Within R
2.10.2
Outside of R
2.11
Summary and Takeaways
3
Importing Data into R with readr
3.1
Instructions
3.2
Learning Objectives
3.3
Set Up
3.4
Basics Of Importing a CSV File Into R
3.4.1
Method 1: Setting a Different Working Directory
3.4.2
Method 2: Copying the Exact Pathway of the File
Try it yourself 3.1
3.4.3
Key Notes About Importing Data into R
Try it yourself 3.2
3.4.4
Column Specification
Try it yourself 3.3
3.5
More Arguments Of read_csv
3.5.1
Skip
Try it yourself 3.4
3.5.2
Remove Header & Header Names
3.5.3
Missing Values
3.6
Importing Other File Types into R
3.6.1
Text file (txt)
3.6.2
Excel file (xlsx)
Try it yourself 3.5
3.6.3
XPT File Extension
3.6.4
Statistical Analysis Software (SAS)
3.7
Exporting the Data Frame From R
3.8
Summary and Takeaways
4
Introduction to NHANES
4.1
Instructions
4.2
Learning Objectives
4.3
Introduction to NHANES
4.4
Importing NHANES dataset from website
4.5
Importing NHANES dataset from R package: nhanesA
Try it yourself 4.1]
4.1
4.5.1
Other packages in R
4.5.2
Alternative ways to download NHANES
4.6
Summary and Takeaways
5
Data Analysis with dplyr
5.1
Instructions
5.2
Learning Objectives
5.3
Set up
5.3.1
Install and load packages
5.3.2
Set working directory
5.3.3
Import dataset
5.3.4
Explore our dataset
5.4
Dataset Preparation
Try it yourself 5.1
Try it yourself 5.2
5.5
Filter
Try it yourself 5.3
5.6
Re-order the Rows
Try it yourself 5.4
5.7
Add new variables
Try it yourself 5.5
5.8
Summary Statistics and group_by
Try it yourself 5.6
5.8.1
Group_by() extension
Try it yourself 5.7
Try it yourself 5.8
5.9
Pipe
Try it yourself 5.9
5.10
Summary of dealing with missing values
5.11
Alternatives to NHANESTranslate()
5.11.1
case_when()
5.12
Translating NHANES using
case_when()
5.13
recode()
from dplyr
5.14
recode()
from car
5.15
Summary and Takeaways
6
Data Visualization with ggplot2
6.1
Instructions
6.2
Learning Objectives
6.3
Set Up
6.3.1
Loading required packages
6.3.2
Importing Data
6.4
ggplot() and Point Geometrics
6.4.1
Point Geometrics
Try it yourself 6.1
6.4.2
Aesthetics
Try it yourself 6.2
6.5
Multiple Geometric Functions under one ggplot
6.6
Other Geometric Functions
6.6.1
Bar graph
6.6.2
Line Graph
6.6.3
Boxplot
6.6.4
Frequency Polygon
Try it yourself 6.3
6.7
Facet Functions
Try it yourself 6.4
6.8
Customizing Graph Elements
Try it yourself 6.5
6.9
Saving Our Graphs
6.10
Summary and Takeaways
7
Date & Time Data with lubridate
7.1
Instructions
7.2
Learning Objectives
7.3
Set Up
7.4
Exploring Friends Visits Dataset
7.5
Creating Date/Time Data
7.5.1
Strings
Try it yourself 7.1
7.5.2
Existing Date/Time Data
7.5.3
Dataset
Functions Debunked
Try it yourself 7.2
7.6
Retrieving Information from Date/Time Data
7.6.1
Year
7.6.2
Month
7.6.3
Week
Try it yourself 7.3
7.6.4
Plotting Retrieved Information
Try it yourself 7.4
7.7
Updating & Plotting Date/Time Data
7.7.1
Update
Try it yourself 7.5
7.7.2
Plotting Date/Time
Try it yourself 7.6
7.8
Arithmetic Operators with Date/Time
7.8.1
Basic Arithmetic
7.8.2
Account for Leap Years and Daylight Savings
7.9
Summary and Takeaways
8
Data Summary with tableone
8.1
Instructions
8.2
Learning Objectives
8.3
Set Up
8.4
What is tableone?
8.5
Creating a tableone
8.5.1
CreateTableOne
8.5.2
Solution 1: nhanesTranslate & CreateTableOne
Try it yourself 8.1
8.5.3
Solution 2: Identify Numerical Categorical Data
Try it yourself 8.2
8.6
Other Arguments to Customize tableone
8.6.1
Show All Levels
8.6.2
Nonnormal
Try it yourself 8.3
8.6.3
Show Categorical or Continuous Variables Only
8.6.4
Strata
Try it yourself 8.4
8.7
Export tableone
8.8
Alternatives to tableone
8.8.1
base R
8.8.2
Hmisc
8.8.3
psych
8.8.4
desctable
8.8.5
skimr
8.9
Summary and Takeaways
9
Appendix: Exercise Solutions
9.1
Tutorial 2: Introduction to R
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
9.2
Tutorial 3: Importing Data into R with readr
3.1
3.2
3.3
3.4
3.5
9.3
Tutorial 4: Introduction to NHANES
4.1
9.4
Tutorial 5: Data Analysis with dplyr
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
9.5
Tutorial 6: Data Visualization with ggplot2
6.1
6.2
6.3
6.4
9.6
Tutorial 7: Date and Time Data with lubridate
7.1
7.2
7.3
7.4
7.5
7.6
9.7
Tutorial 8: Data Summary with tableone
8.1
8.2
8.3
8.4
References
Ehsan Karim
Introduction to R for health data analysis
References
Wickham, Hadley, and Garrett Grolemund. 2016.
R for Data Science: Import, Tidy, Transform, Visualize, and Model Data
. " O’Reilly Media, Inc.".