Conditional mutating, case_when | Data untangled: transforming and cleaning data with R (lesson 4)
Channel: The GRAPH Courses
Date: 2023-03-02

👋 LESSON MATERIALS 🛑

Get the data, scripts, PDF notes and quizzes for this lesson from our website: 
https://thegraphcourses.org/courses/data-untangled-beta/topics/conditional-mutate-2/

If this is your first time coding along with us, watch this quick video to see how it works: https://youtu.be/xTsdNpeY2ak

Chapters
00:00 Intro
02:11 Datasets
04:15 Introducing case_when
09:31 The TRUE default argument
12:13 Matching NA’s with is.na()
14:34 Keeping default values of a variable
19:02 Multiple conditions, single variable
24:23 Multiple conditions, multiple variables
29:11 Order of priority of conditions
41:00 Binary conditions: dplyr::if_else()
43:35 Wrap up

Learning objectives
1. You can transform or create new variables based on conditions using dplyr::case_when()
2. You know how to use the TRUE condition in case_when() to match unmatched cases.
3. You can handle NA values in case_when() transformations.
4. You understand how to keep the default values of a variable in a case_when() formula
5. You can write case_when() conditions involving multiple comparators and multiple variables.
6. You understand case_when() conditions priority order.
7. You can use dplyr::if_else() for binary conditional assignment.


----------------

And follow us on social media to get the latest updates!
Twitter: https://twitter.com/theGRAPHnetwork
LinkedIn: https://www.linkedin.com/company/the-graph-network