Data Wrangling
Six Main Verbs
Announcements
This week in MSCS
- Thursday 11:15am: Coffee Break!
Looking Ahead
- Week 5: Data Wrangling
- Week 6: Data Wrangling
- Week 7: Mini Project/Capstone Days!
- Week 8: Midterm Review/Midterm
Due this Week
- Assignment 4 (Effective, Spatial Viz) on Weds [via Moodle]
- At least 1 Tidy Tuesday (TT) by next Friday [via Moodle, TT4 or TT5]
Learning Goals
- Understand and be able to use the following verbs appropriate:
select
, mutate
, filter
, arrange
, summarize
, group_by
- Develop working knowledge of working with dates and
lubridate
functions
Six Main Verbs
Verbs that change the variables (columns) but not the cases (rows)
Verbs that change the cases (rows) but not the variables (columns)
Grouped summaries
Six Main Verbs
Verbs that change the variables (columns) but not the cases (rows)
- select
- Action: Provides a subset of variables
- Inputs: data, variable names
- mutate
- Action: creates new variables
- Inputs: data, new_variable_name = how_you_define_new_var
- Examples: mutate(data, var2 = var^2)
Verbs that change the cases (rows) but not the variables (columns)
- filter
- Action: shows subset of rows
- Inputs: data, Boolean conditions based on variables
- Examples: filter(data, year > 2000)
- arrange
- Action: sorts rows
- Inputs: data, variable names, desc(variable name) if by descending order
- Examples: arrange(data, desc(n))
- summarize
- Action: collapses rows and calculates a summary
- Inputs: data, new_variable_name = expression_used_to_summarize
- Example: summarize(data, avgHeight = mean(height))
- group_by
- Action: creates a grouping structure within data
- Inputs: data, names of variables to define grouping structure
- Example: data %>% group_by(sport) %>% summarize(avgHeight = mean(height))
Template File
Download a template .Rmd of this activity. Put the file in a Assignment_05
folder within your COMP_STAT_112
folder.
- This .Rmd only contains examples that we’ll work on in class and exercises you’ll finish for Assignment 5.
Rest of Class
Continue working on the activity; check in with your classmates.
Don’t leave anyone left struggling alone!
After Class
This activity is all code, no interpretations.
There are 12 exercises to give you plenty of practice with these important six tasks!
You’ll finish the activity for Assignment 5.