{"id":34,"date":"2026-03-03T06:51:46","date_gmt":"2026-03-03T06:51:46","guid":{"rendered":"https:\/\/gigz.pk\/r\/?post_type=lesson&#038;p=34"},"modified":"2026-04-01T10:57:11","modified_gmt":"2026-04-01T10:57:11","slug":"mutate-and-summarize-functions","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/r\/lesson\/mutate-and-summarize-functions\/","title":{"rendered":"Mutate and Summarize Functions"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>mutate()<\/code> and <code>summarise()<\/code> functions in R, provided by the <code>dplyr<\/code> package, are essential for creating new variables, transforming data, and generating summary statistics. Mastering these functions allows you to manipulate datasets efficiently and extract meaningful insights.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>1. The mutate() Function<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><code>mutate()<\/code> is used to create new columns or modify existing ones in a data frame or tibble.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Creating New Columns<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">library(dplyr)data &lt;- data.frame(<br>  Name = c(\"Alice\", \"Bob\", \"Charlie\"),<br>  Score = c(90, 85, 88),<br>  Age = c(25, 30, 28)<br>)# Add a new column for Score plus bonus points<br>data &lt;- mutate(data, ScoreBonus = Score + 5)# Add a logical column to indicate if Score is passing (&gt;= 88)<br>data &lt;- mutate(data, Passed = Score &gt;= 88)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Modifying Existing Columns<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can also update existing columns:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data &lt;- mutate(data, Age = Age + 1)  # Increase all ages by 1<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>2. The summarise() Function<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><code>summarise()<\/code> is used to calculate summary statistics for a dataset. It is often combined with <code>group_by()<\/code> for grouped summaries.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Basic Summary Statistics<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"># Calculate average score and maximum age<br>summarise(data, AverageScore = mean(Score), MaxAge = max(Age))<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Grouped Summaries with group_by()<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">data &lt;- mutate(data, Passed = Score &gt;= 88)# Group by Passed status and calculate average age and score<br>data %&gt;%<br>  group_by(Passed) %&gt;%<br>  summarise(<br>    AverageAge = mean(Age),<br>    AverageScore = mean(Score)<br>  )<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This calculates the average age and score for students who passed and those who didn\u2019t.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>3. Using mutate() and summarise() Together<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">You can combine these functions in a pipeline to create new variables and then summarize them:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data %&gt;%<br>  mutate(ScoreAdjusted = Score + 2) %&gt;%<br>  summarise(AverageAdjusted = mean(ScoreAdjusted))<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>4. Advantages of mutate() and summarise()<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Simplifies creation of new columns and transformations<\/li>\n\n\n\n<li>Provides powerful tools for grouped statistical analysis<\/li>\n\n\n\n<li>Works seamlessly with the pipe operator <code>%&gt;%<\/code> for readable and efficient workflows<\/li>\n\n\n\n<li>Essential for preparing datasets for visualization or modeling<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><code>mutate()<\/code> and <code>summarise()<\/code> are core functions in R for transforming and analyzing data. <code>mutate()<\/code> allows you to add or modify variables, while <code>summarise()<\/code> helps generate key statistics and insights. Mastering these functions makes your data analysis workflow more efficient, organized, and insightful.<\/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 > Mutate and Summarize Functions<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1775041008060\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":11,"template":"","class_list":["post-34","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>Mutate and Summarize Functions - Analyze Deep. Visualize Better. Build with R.<\/title>\n<meta name=\"description\" content=\"Learn how to use mutate and summarise in R for data transformation. Master creating new columns and generating summary statistics.\" \/>\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=\"Mutate and Summarize Functions - Analyze Deep. Visualize Better. Build with R.\" \/>\n<meta property=\"og:description\" content=\"Learn how to use mutate and summarise in R for data transformation. Master creating new columns and generating summary statistics.\" \/>\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:57:11+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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/lesson\\\/mutate-and-summarize-functions\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Mutate and Summarize Functions - Analyze Deep. Visualize Better. Build with R.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/#website\"},\"datePublished\":\"2026-03-03T06:51:46+00:00\",\"dateModified\":\"2026-04-01T10:57:11+00:00\",\"description\":\"Learn how to use mutate and summarise in R for data transformation. Master creating new columns and generating summary statistics.\",\"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 > Mutate and Summarize Functions\"}]},{\"@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":"Mutate and Summarize Functions - Analyze Deep. Visualize Better. Build with R.","description":"Learn how to use mutate and summarise in R for data transformation. Master creating new columns and generating summary statistics.","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":"Mutate and Summarize Functions - Analyze Deep. Visualize Better. Build with R.","og_description":"Learn how to use mutate and summarise in R for data transformation. Master creating new columns and generating summary statistics.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Analyze Deep. Visualize Better. Build with R.","article_modified_time":"2026-04-01T10:57:11+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/r\/lesson\/mutate-and-summarize-functions\/","url":"https:\/\/gigz.pk\/","name":"Mutate and Summarize Functions - Analyze Deep. Visualize Better. Build with R.","isPartOf":{"@id":"https:\/\/gigz.pk\/r\/#website"},"datePublished":"2026-03-03T06:51:46+00:00","dateModified":"2026-04-01T10:57:11+00:00","description":"Learn how to use mutate and summarise in R for data transformation. Master creating new columns and generating summary statistics.","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 > Mutate and Summarize Functions"}]},{"@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\/34","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=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}