Professional Documents
Culture Documents
Beginner R - Q4D - ULSOPH - Lecture 4
Beginner R - Q4D - ULSOPH - Lecture 4
Lecture
Beginner R for
Public Health
Practitioners and
Researchers in
Liberia
R Coding and Biostatistics Short Course Series
Laura Skrip, PhD, MPH
Today’s Plan
Content Topics Time (Minutes) Skills
Practice Activity (30 minutes)
Defining new 60 • Making space for new objects
variables (cont.) • Using the which function to subset and redefine
existing variables
• Creating embedded for and if loops to create loops
based on conditional statements
Linking datasets 5 • Linking two datasets based on a common variable
using the cbind() and merge() functions
Introducing the 20 • Installing new packages
ggplot2 package
Preparing for Course Conclusion (5 minutes)
BMI Classification
< 18.5 Underweight
18.5 to <25 Healthy
25 to <30 Overweight
30+ Obesity
3 Beginner R Course - Developed by Laura Skrip
Activity: Cleaning data with the which
function
Hints:
• Create ‘space’ for a new variable.
• Example 1: Suppose you had a dataset with an Age variable. Age is often collected
as a numeric variable, but sometimes it is helpful to categorize age. You may want
to create a variable that reflects age groups known to be at differential risk of a
disease or condition.
Action: if age is less than 45, use the category ‘<45’ in the Age_Group variable and if
age is 45 or above, use the category ‘≥45’.
• What search terms could we use to identify the function for accomplishing this task?
• What search terms could we use to identify the function for accomplishing this task?
• https://www.r-graph-gallery.com/histogram_several_group.html
16 Beginner R Course - Developed by Laura Skrip
Final Steps
for Beginner R
Demonstrating what you have learned and
where we are going
• Scheduling…