{"id":32,"date":"2026-03-03T06:47:56","date_gmt":"2026-03-03T06:47:56","guid":{"rendered":"https:\/\/gigz.pk\/r\/?post_type=lesson&#038;p=32"},"modified":"2026-04-01T10:51:36","modified_gmt":"2026-04-01T10:51:36","slug":"using-dplyr-for-data-manipulation","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/r\/lesson\/using-dplyr-for-data-manipulation\/","title":{"rendered":"Using dplyr for Data Manipulation"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><code>dplyr<\/code> is one of the most popular R packages for data manipulation. It provides a set of intuitive functions that allow you to filter, arrange, select, mutate, and summarize datasets efficiently. Learning <code>dplyr<\/code> is essential for modern data analysis in R.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>1. Installing and Loading dplyr<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Before using <code>dplyr<\/code>, install and load the package:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">install.packages(\"dplyr\")   # Install dplyr<br>library(dplyr)              # Load dplyr<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>2. Core dplyr Functions<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><code>dplyr<\/code> provides several key verbs to manipulate data frames or tibbles:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>a) select()<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>select()<\/code> is used to choose specific columns from a dataset:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data &lt;- data.frame(Name=c(\"Alice\",\"Bob\",\"Charlie\"),<br>                   Age=c(25,30,28),<br>                   Score=c(90,85,88))select(data, Name, Score)   # Select only Name and Score columns<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>b) filter()<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>filter()<\/code> is used to filter rows based on conditions:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">filter(data, Age &gt; 26)      # Returns rows where Age &gt; 26<br>filter(data, Score &gt;= 88)   # Rows with Score 88 or higher<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>c) arrange()<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>arrange()<\/code> is used to sort rows by one or more columns:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">arrange(data, Age)           # Sort by Age ascending<br>arrange(data, desc(Score))   # Sort by Score descending<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>d) mutate()<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>mutate()<\/code> adds new columns or modifies existing ones:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mutate(data, Passed = Score &gt;= 85)   # Adds a logical column Passed<br>mutate(data, ScoreBonus = Score + 5) # Adds 5 points to Score<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>e) summarise() and group_by()<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>summarise()<\/code> is used to calculate summary statistics, often combined with <code>group_by()<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">group_by(data, Passed = Score &gt;= 85) %&gt;%<br>  summarise(AverageAge = mean(Age), MaxScore = max(Score))<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This groups the data by the <code>Passed<\/code> status and calculates the average age and maximum score for each group.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>3. The Pipe Operator <code>%&gt;%<\/code><\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The pipe operator <code>%&gt;%<\/code> allows chaining multiple operations together in a readable way:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data %&gt;%<br>  filter(Age &gt; 25) %&gt;%<br>  arrange(desc(Score)) %&gt;%<br>  select(Name, Score)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This filters, sorts, and selects columns in a single, readable statement.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>4. Advantages of Using dplyr<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Intuitive and readable syntax<\/li>\n\n\n\n<li>Works efficiently with large datasets<\/li>\n\n\n\n<li>Seamless integration with tibbles and the tidyverse ecosystem<\/li>\n\n\n\n<li>Simplifies common data manipulation tasks like filtering, summarizing, and mutating<\/li>\n<\/ul>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1775040607023\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><code>dplyr<\/code> is a powerful package for transforming and analyzing data in R. By mastering functions like <code>select()<\/code>, <code>filter()<\/code>, <code>arrange()<\/code>, <code>mutate()<\/code>, and <code>summarise()<\/code>, you can perform complex data manipulations with minimal code. Using the pipe operator <code>%&gt;%<\/code> makes your workflow clean, efficient, and easy to read.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/r\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">R Programming (R Lang) > Data Manipulation in R > Using dplyr for Data Manipulation<\/span><\/span><\/div>","protected":false},"menu_order":9,"template":"","class_list":["post-32","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using dplyr for Data Manipulation - Analyze Deep. Visualize Better. Build with R.<\/title>\n<meta name=\"description\" content=\"Learn how to use dplyr for data manipulation in R with examples. Master select, filter, mutate, summarise, and the pipe operator.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using dplyr for Data Manipulation - Analyze Deep. Visualize Better. Build with R.\" \/>\n<meta property=\"og:description\" content=\"Learn how to use dplyr for data manipulation in R with examples. Master select, filter, mutate, summarise, and the pipe operator.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Analyze Deep. Visualize Better. Build with R.\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-01T10:51:36+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/lesson\\\/using-dplyr-for-data-manipulation\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Using dplyr for Data Manipulation - Analyze Deep. Visualize Better. Build with R.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/#website\"},\"datePublished\":\"2026-03-03T06:47:56+00:00\",\"dateModified\":\"2026-04-01T10:51:36+00:00\",\"description\":\"Learn how to use dplyr for data manipulation in R with examples. Master select, filter, mutate, summarise, and the pipe operator.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/r\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"R Programming (R Lang) > Data Manipulation in R > Using dplyr for Data Manipulation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/r\\\/\",\"name\":\"Analyze Deep. Visualize Better. Build with R.\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/r\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using dplyr for Data Manipulation - Analyze Deep. Visualize Better. Build with R.","description":"Learn how to use dplyr for data manipulation in R with examples. Master select, filter, mutate, summarise, and the pipe operator.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/","og_locale":"en_US","og_type":"article","og_title":"Using dplyr for Data Manipulation - Analyze Deep. Visualize Better. Build with R.","og_description":"Learn how to use dplyr for data manipulation in R with examples. Master select, filter, mutate, summarise, and the pipe operator.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Analyze Deep. Visualize Better. Build with R.","article_modified_time":"2026-04-01T10:51:36+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/r\/lesson\/using-dplyr-for-data-manipulation\/","url":"https:\/\/gigz.pk\/","name":"Using dplyr for Data Manipulation - Analyze Deep. Visualize Better. Build with R.","isPartOf":{"@id":"https:\/\/gigz.pk\/r\/#website"},"datePublished":"2026-03-03T06:47:56+00:00","dateModified":"2026-04-01T10:51:36+00:00","description":"Learn how to use dplyr for data manipulation in R with examples. Master select, filter, mutate, summarise, and the pipe operator.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/r\/"},{"@type":"ListItem","position":2,"name":"R Programming (R Lang) > Data Manipulation in R > Using dplyr for Data Manipulation"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/r\/#website","url":"https:\/\/gigz.pk\/r\/","name":"Analyze Deep. Visualize Better. Build with R.","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/r\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/lesson\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/media?parent=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}