R Tutorial: The filter and arrange verbs
Key Takeaways
The video demonstrates the use of dplyr verbs, specifically filter and arrange, to manipulate and explore data in R.
Full Transcript
you've learned how to select particular variables or columns that you're interested in now you'll explore the data to find interesting observations or rows we start with code for selecting four columns of interest the state county population and unemployment rate we could start by assigning that to the variable counties underscore selected will work with that variable from now on right now notice that the observations are in alphabetical order by state and county we might instead be interested in the counties that have the highest population the arranged verb sorts your data based on one or more variables you can start with your counties selected variable then the pipe operator then arranged inside the parentheses put population to specify the variable you want to sort by this shows us the counties with the lowest population which are indeed pretty small one county in Hawaii has only 85 people we might be more interested in the counties with the highest population to find these you change your code only a little bit add descending around population it looks like the highest population is Los Angeles California which is one of the biggest cities in the United States a range is thus a useful verb for finding the most interesting observations in the data set from now on we'll keep showing multiple verbs at a time to get you in the habit of typing many verbs together another useful verb is filter you can use the filter verb to extract only particular observations from a dataset based on a condition recall that after your first verb you can add a pipe operator then add another verb you can pipe any number of verbs together to transform your data set for example after the arranged you could add filters state equals equals quote New York to get only counties in the state of New York notice that the observations are filtered but they're still sorted by population thanks to your arranged besides equals equals you can filter based on logical operators like less than or greater than for example you could filter for counties that have an unemployment rate of less than 6% the condition in the filter would be unemployment less than 6 this tells you that the largest counties with an unemployment rate below 6% are Fairfax Virginia and Salt Lake Utah finally you can combine multiple conditions together in a filter you filtered for the state of New York and for unemployment below 6% but you can do both at the same time if you separate them with a comma it looks like only a few counties in New York have an unemployment rate that low throughout the court
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/data-manipulation-with-dplyr at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
You've learned how to select particular variables, or columns, that you're interested in. Now you'll explore the data to find interesting observations, or rows.
We start with code for selecting four columns of interest: the state, county, population, and unemployment rate. We could start by assigning that to the variable counties-underscore-selected. We'll work with that variable from now on.
Right now, notice that the observations are in alphabetical order by state and county.
We might instead be interested in the counties that have the highest population.
The arrange() verb sorts your data based on one or more variables. You can start with your counties selected variable, then the pipe operator, then arrange. Inside the parentheses, put population to specify the variable you want to sort by.
This shows us the counties with the lowest population, which are indeed pretty small: one county in Hawaii has only 85 people.
We might be more interested in the counties with the highest population. To find these, you'd change your code only a little bit: add desc() around population.
It looks like the highest population is Los Angeles, California, which is one of the biggest cities in the United States. Arrange is thus a useful verb for finding the most interesting observations in a dataset. From now on, we'll keep showing multiple verbs at a time, to get you in the habit of piping many verbs together.
Another useful verb is filter(). You can use the filter verb to extract only particular observations from a dataset, based on a condition. Recall that after your first verb, you can add a pipe operator, then add another verb. You can pipe any number of verbs together to transform your dataset.
For example, after the arrange(), you could add filter
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: Data Literacy
View skill →Related Reads
📰
📰
📰
📰
How I Built a Blank Page Detector for PDFs with Vue 3 and Canvas
Dev.to · sunshey
What I Learned Building an AI Resume Optimizer — And What Recruiters Actually Told Me
Dev.to · dayu2333-jinyul
The Language Barrier That Made Me Use AI Better
Dev.to · FromZeroToShip
I Stopped Running Playwright in Cron and Built a Screenshot Archive Instead
Dev.to · Cizze R
🎓
Tutor Explanation
DeepCamp AI