R Programming: Data Manipulation with dplyr (Step-by-Step)

Coursera · Beginner ·🛠️ AI Tools & Apps ·8mo ago

Key Takeaways

Learning data manipulation with dplyr in R, including filter, select, and arrange functions

Full Transcript

Welcome. I'm glad you're here and ready to explore some incredibly useful R functions from the dlier package. Filter function, select function, and arrange function. By the end of this screencast, you'll be comfortable using these core functions to handle common data tasks like isolating relevant records from your data set, selecting only the columns required for analysis, and effectively sorting your records. I promise this is simpler than it may initially seem. By the end of our time together, you'll feel confident applying these methods to scenarios you regularly encounter and work. To start, let's quickly confirm you have everything you need. If you don't yet have the deeply package installed, that's perfectly okay. You can install it easily by using install.packages command like this. Type in dlier in the argument. As you can see, it is downloading. Once installed, go ahead and load the package using the library function as you can see above. This will help you proceed. In this demonstration, we'll use the built-in empty cars data set. It's a compact, straightforward data set included in R, ideal for practicing new techniques. Let's take a brief look at how it looks. As you see, we've got columns like MPG or miles per gallon, CL, number of cylinders, and HP horsepower. You may spot a lot of similarity with data from your own work. Perhaps product specifications, employee performance metrics, or even monthly sales figures. Let's start with the filter function. This function allows you to keep only those rows that satisfy certain conditions. For example, if you're interested in vehicles that have an miles per gallon value higher than 20, you'd run the following. Let's define that as high efficiency cars. Assign it the filter function. First we put our data set name empty cars followed by a comma and then the condition miles per gallon greater than 20. Now we print it afterwards. Let's see how it looks. Let's briefly unpack that. The first argument is always the original data set empty cars. And the second argument defines our condition miles per gallon greater than 20. In other words, we're instructing R to return only rows greater than 20 for miles per gallon. This is simpler than it may initially look. And after trying it once or twice yourself, you'll see it's straightforward intuitive. Here is the data set. Now, a quick tip to help prevent common mistakes here. When setting equality conditions in R, always use a double equal sign. In our current example, comparing with greater than, this is not necessary, but it's worth remembering for future cases. Next, let's talk about the select function. The select function simplifies your data by keeping only the columns needed for your analysis. Suppose you're preparing a quick efficiency report or only need miles per gallon, cylinder, and horsepower columns from the original data set. To achieve this, you specify the columns in select function. Let's call this new data set or subset of data car summary. We use a select function followed by data set empty cars then all the columns that we're interested in mpg c and hp. Let's print this. See how the data only selected miles per gallon, cylinder, and horsepower. In practice, select helps cut down clutter, simplifying your reports and making large data sets more manageable. A small but useful condition, additional tip here, to remove unwanted columns instead of having to pick any columns manually, you can use the minus sign in front of column names you want to exclude. For example, select empty cars. Mine has gear. Let's type that out. Select empty cars followed by minus gear minus am. Excellent. Now moving on to the range function. The range function sorts your rows based on a specified column. Suppose you want to organize your data by miles per gallon in ascending order. You type sorted cars, assign it the arrange function, specify our data empty cars, followed by miles per gallon. Now let's print and see how this looks. See how miles per gallon is sorted in an ascending manner. But what if you need to determine cars with the highest miles per gallon at the tops? Perhaps to respond directly to a manager's inquiry about top performer vehicles. Arranging in descending order is just one simple step away and again simpler than it may initially sound. Let's clear our terminal and write our query in a different way. Let's call it sorted cars descending. assign it the arrange function. Select our data set empty cars but adding the descending function to our miles per gallon. Let's print this and see how it looks. See how it's now in descending order with the Toyota Corolla being at the top. Remember the arrange sorts ascending by default, but you only need to wrap your chosen column in descending function to reverse this order. It becomes intuitive quickly with practice. I'm confident you'll master this comfortably. Let's briefly touch on a best practice that's coming among our professionals. Combining multiple commands into a logical pipeline using what's known as a pipe operator. percent sign greater than percent sign. This operator helps you write your data task cleanly, almost as though you're guiding a colleague step by step through the analysis. Let's combine all the steps we practiced earlier in one clear sequence. We'll filter for cars with miles per gallon above 20. Select the columns miles per gallon, cylinder, and horsepower. And then arrange the resulting subset by horsepower highest first. First, let's define our subset empty cars adj for adjusted. We will do our assignment operator. Use our data set empty cars. Use the pipe operator followed by the filter function with miles per gallon over 20. Use another pipe operator followed by the select function with miles per gallon cy lp. Then we will use a final pipe operator to use the arrange function and put our condition of descending horsepower. Let's see how this looks. Notice that we only have our three columns that we selected where miles per gallon is above 20 and it's sorted in descending order by the horsepower column. As you see, writing code this way greatly improves readability for yourself and other colleagues who might review it. It even helps those developing familiarity with R quick quickly grasp your overall intention. A brief caution that can save you from frustration later. Ensure your pipe operator appears at the end of each line except the final operation of your sequence. If you encounter any errors running code like this, that's a first thing to double check, an easy fix. Before wrapping up, another brief practical tip. If your workflow involves typing repetitive commands, using a code assisted tool such as GitHub Copilot may help accelerate your scripting. Remember to always confirm carefully that your final code aligns precisely with your intended analysis. In this screencast, you've been introduced to practical ways of leveraging filter function, select function, and arrange function with confidence and clarity. You're now positioned to apply those valuable tools directly to your task at work, strengthening your data skills step by step. Keep going and practice applying these functions to realistic scenarios to consolidate your understanding. Soon enough, you'll find yourself handling your data tasks clearly and efficiently. You've got this.

Original Description

Learn three powerful dplyr functions for data manipulation in R. This Microsoft tutorial covers filter(), select(), and arrange() with practical examples using the mtcars dataset. Perfect for beginners and intermediate R programmers. 🕐 Timestamps: 0:00 - Introduction 0:45 - Installing dplyr Package 1:26 - Understanding mtcars Dataset 2:07 - Filter Function Basics 3:35 - Select Function Tutorial 4:48 - Arrange Function Demo 6:54 - Combining Commands with Pipes 8:37 - Best Practices & Tips 9:12 - Conclusion 🎓 This is a course preview of the *Microsoft R Programming for Everyone Professional Certificate* on Coursera. With the complete program, you'll: • Learn to write efficient R code • Collaborate through GitHub • Analyze complex datasets • Use AI tools to enhance productivity • No prior programming experience needed • Build a professional portfolio of hands-on projects using real datasets in a Microsoft development environment Enroll now to access the complete 5-course program 👇 https://bit.ly/4hSuvEM #RProgramming #DataScience #dplyr
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Coursera · Coursera · 0 of 60

← Previous Next →
1 Principles of Obesity Economics with Professor Kevin Frick
Principles of Obesity Economics with Professor Kevin Frick
Coursera
2 Introduction to the U.S. Food System: Perspectives from Public Health by John Hopkins University
Introduction to the U.S. Food System: Perspectives from Public Health by John Hopkins University
Coursera
3 E-learning and Digital Cultures
E-learning and Digital Cultures
Coursera
4 Equine Nutrition with Jo-Anne Murray
Equine Nutrition with Jo-Anne Murray
Coursera
5 Coursera Meetup BBQ
Coursera Meetup BBQ
Coursera
6 Contraception: Choices, Culture and Consequences with Jerusalem Makonnen
Contraception: Choices, Culture and Consequences with Jerusalem Makonnen
Coursera
7 Nutrition for Health Promotion and Disease Prevention with Katie Clark
Nutrition for Health Promotion and Disease Prevention with Katie Clark
Coursera
8 Information Security and Risk Management in Context with Dr. Barbara Endicott-Popovsky
Information Security and Risk Management in Context with Dr. Barbara Endicott-Popovsky
Coursera
9 Contraception: Choices, Culture and Consequences with Jerusalem Makonnen
Contraception: Choices, Culture and Consequences with Jerusalem Makonnen
Coursera
10 Writing in the Sciences with Kristin Sainani
Writing in the Sciences with Kristin Sainani
Coursera
11 Economic Issues, Food, and You with Jennifer Clark
Economic Issues, Food, and You with Jennifer Clark
Coursera
12 Leading Strategic Innovation and Creativity in Organizations with David A. Owens, PhD
Leading Strategic Innovation and Creativity in Organizations with David A. Owens, PhD
Coursera
13 Useful Genetics with Professor Rosie Redfield
Useful Genetics with Professor Rosie Redfield
Coursera
14 A History of the World since 1300!!!! with Jeremy Adelman
A History of the World since 1300!!!! with Jeremy Adelman
Coursera
15 Microeconomics  with Richard McKenzie
Microeconomics with Richard McKenzie
Coursera
16 Discrete Optimization with Professor Pascal Van Hentenryck
Discrete Optimization with Professor Pascal Van Hentenryck
Coursera
17 Leading Strategic Innovation and Creativity in Organizations with David A. Owens, PhD
Leading Strategic Innovation and Creativity in Organizations with David A. Owens, PhD
Coursera
18 Science from Superheroes to Global Warming with Michael Dennin
Science from Superheroes to Global Warming with Michael Dennin
Coursera
19 Introduction to Digital Sound Design with Steve Everett by Emory University
Introduction to Digital Sound Design with Steve Everett by Emory University
Coursera
20 Women and the Civil Rights Movement with Dr. Elsa Barkley Brown
Women and the Civil Rights Movement with Dr. Elsa Barkley Brown
Coursera
21 Galaxies and Cosmology with S. George Djorgovski
Galaxies and Cosmology with S. George Djorgovski
Coursera
22 Science, Technology, and Society in China I, II, and III: Basic Concepts with Naubahar Sharif
Science, Technology, and Society in China I, II, and III: Basic Concepts with Naubahar Sharif
Coursera
23 Introduction to Pharmacy with Kenneth M. Hale, R.Ph., Ph.D.
Introduction to Pharmacy with Kenneth M. Hale, R.Ph., Ph.D.
Coursera
24 AIDS with Kimberley Sessions Hagen, EdD
AIDS with Kimberley Sessions Hagen, EdD
Coursera
25 Health Informatics in the Cloud with Mark Braunstein
Health Informatics in the Cloud with Mark Braunstein
Coursera
26 Songwriting with Pat Pattison by Berklee College of Music
Songwriting with Pat Pattison by Berklee College of Music
Coursera
27 Software Defined Networking with Dr. Nick Feamster
Software Defined Networking with Dr. Nick Feamster
Coursera
28 Epigenetic Control of Gene Expression with Dr Marnie Blewitt
Epigenetic Control of Gene Expression with Dr Marnie Blewitt
Coursera
29 Guitar for Beginners - Introduction to Guitar with Thaddeus Hogarth by Berklee College of Music
Guitar for Beginners - Introduction to Guitar with Thaddeus Hogarth by Berklee College of Music
Coursera
30 Organizational Analysis with Daniel McFarland
Organizational Analysis with Daniel McFarland
Coursera
31 Scientific Computing with J. Nathan Kutz
Scientific Computing with J. Nathan Kutz
Coursera
32 Jazz Improvisation - Introduction to Improvisation with Gary Burton by Berklee College of Music
Jazz Improvisation - Introduction to Improvisation with Gary Burton by Berklee College of Music
Coursera
33 Principles of Economics for Scientists with Antonio Rangel
Principles of Economics for Scientists with Antonio Rangel
Coursera
34 Introduction to Music Production with Loudon Stearns by Berklee College of Music
Introduction to Music Production with Loudon Stearns by Berklee College of Music
Coursera
35 Principles of Public Health with Zuzana Bic
Principles of Public Health with Zuzana Bic
Coursera
36 The Science of Gastronomy with King Chow, Lam Lung Yeung by HKUST
The Science of Gastronomy with King Chow, Lam Lung Yeung by HKUST
Coursera
37 The Language of Hollywood: Storytelling, Sound, and Color with Scott Higgins by Wesleyan University
The Language of Hollywood: Storytelling, Sound, and Color with Scott Higgins by Wesleyan University
Coursera
38 Nutrition and Physical Activity for Health with John M. Jakicic, Ph.D., and Amy D. Rickman,...
Nutrition and Physical Activity for Health with John M. Jakicic, Ph.D., and Amy D. Rickman,...
Coursera
39 Nutrition, Health, and Lifestyle: Issues and Insights with Jamie Pope, MS, RD, L
Nutrition, Health, and Lifestyle: Issues and Insights with Jamie Pope, MS, RD, L
Coursera
40 Survey of Music Technology with Jason Freeman by Georgia Institute of Technology
Survey of Music Technology with Jason Freeman by Georgia Institute of Technology
Coursera
41 Exercise Physiology: Understanding the Athlete Within with Mark Hargreaves
Exercise Physiology: Understanding the Athlete Within with Mark Hargreaves
Coursera
42 Canine Theriogenology for Dog Enthusiasts with Margaret V. Root
Canine Theriogenology for Dog Enthusiasts with Margaret V. Root
Coursera
43 Web Intelligence and Big Data with Gautam Shroff
Web Intelligence and Big Data with Gautam Shroff
Coursera
44 Critical Perspectives on Management with  Rolf  Strom-Olsen
Critical Perspectives on Management with Rolf Strom-Olsen
Coursera
45 El ABC  del emprendimiento esbelto  with Sergio  Ortiz Valdes
El ABC del emprendimiento esbelto with Sergio Ortiz Valdes
Coursera
46 Interprofessional Healthcare Informatics with Karen  Monsen
Interprofessional Healthcare Informatics with Karen Monsen
Coursera
47 Creativity, Innovation, and Change with Jack V. Matson, Darrell Velegol and Kath
Creativity, Innovation, and Change with Jack V. Matson, Darrell Velegol and Kath
Coursera
48 Innovacion educativa con recursos abiertos with Maria Soledad Ramirez Montoya an
Innovacion educativa con recursos abiertos with Maria Soledad Ramirez Montoya an
Coursera
49 Inspiring Leadership through Emotional Intelligence with Richard Boyatzis
Inspiring Leadership through Emotional Intelligence with Richard Boyatzis
Coursera
50 Matematicas y movimiento with
Matematicas y movimiento with
Coursera
51 Sustainability of Food Systems: A Global Life Cycle Perspective with Jason Hill
Sustainability of Food Systems: A Global Life Cycle Perspective with Jason Hill
Coursera
52 Latin American Culture with Enrique Tames
Latin American Culture with Enrique Tames
Coursera
53 Latin American Culture' with undefined
Latin American Culture' with undefined
Coursera
54 Computer Security with Dan Boneh
Computer Security with Dan Boneh
Coursera
55 Introduction to Art: Concepts & Techniques
Introduction to Art: Concepts & Techniques
Coursera
56 Programmed cell death
Programmed cell death
Coursera
57 El ABC  del emprendimiento esbelto
El ABC del emprendimiento esbelto
Coursera
58 Understanding economic policymaking
Understanding economic policymaking
Coursera
59 History of Rock, Part 1 by University of Rochester
History of Rock, Part 1 by University of Rochester
Coursera
60 Pensamiento Cientifico
Pensamiento Cientifico
Coursera

Related Reads

Chapters (9)

Introduction
0:45 Installing dplyr Package
1:26 Understanding mtcars Dataset
2:07 Filter Function Basics
3:35 Select Function Tutorial
4:48 Arrange Function Demo
6:54 Combining Commands with Pipes
8:37 Best Practices & Tips
9:12 Conclusion
Up next
Build an MCP Server with n8n | Full MCP Tutorial
Thomas Janssen
Watch →