{"id":44,"date":"2026-03-03T09:35:54","date_gmt":"2026-03-03T09:35:54","guid":{"rendered":"https:\/\/gigz.pk\/r\/?post_type=lesson&#038;p=44"},"modified":"2026-04-01T11:33:57","modified_gmt":"2026-04-01T11:33:57","slug":"descriptive-statistics","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/r\/lesson\/descriptive-statistics\/","title":{"rendered":"Descriptive Statistics"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Descriptive statistics summarize and describe the main features of a dataset. They provide insights into the distribution, central tendency, variability, and overall patterns of data. R offers built-in functions and packages to calculate descriptive statistics efficiently.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>1. Measures of Central Tendency<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Central tendency indicates the \u201ccenter\u201d of a dataset. Common measures include mean, median, and mode.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>a) Mean<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">scores &lt;- c(90, 85, 88, 92, 75, 80, 95)<br>mean(scores)  # Calculates average score<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>b) Median<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">median(scores)  # Middle value when data is sorted<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>c) Mode<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">R doesn\u2019t have a built-in mode function, but you can define one:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">get_mode &lt;- function(x) {<br>  uniq &lt;- unique(x)<br>  uniq[which.max(tabulate(match(x, uniq)))]<br>}get_mode(scores)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>2. Measures of Dispersion<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Dispersion indicates how spread out the data is.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>a) Range<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">range(scores)  # Minimum and maximum values<br>diff(range(scores))  # Range difference<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>b) Variance<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">var(scores)  # Measures variability<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>c) Standard Deviation<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">sd(scores)  # Square root of variance<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>d) Quantiles<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">quantile(scores)        # Default quartiles<br>quantile(scores, probs = c(0.25, 0.5, 0.75))  # Specific quartiles<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>3. Summary Function<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><code>summary()<\/code> provides a quick overview of numeric data including min, 1st quartile, median, mean, 3rd quartile, and max.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">summary(scores)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>4. Frequency Tables<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">For categorical data, frequency counts and proportions are useful.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">grades &lt;- c(\"A\", \"B\", \"A\", \"C\", \"B\", \"A\")<br>table(grades)           # Counts of each category<br>prop.table(table(grades))  # Proportion of each category<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>5. Using dplyr for Descriptive Statistics<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><code>dplyr<\/code> can summarize data easily:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">library(dplyr)data &lt;- data.frame(<br>  Name = c(\"Alice\",\"Bob\",\"Charlie\",\"David\"),<br>  Score = c(90, 85, 88, 92)<br>)data %&gt;%<br>  summarise(<br>    Average = mean(Score),<br>    Maximum = max(Score),<br>    Minimum = min(Score),<br>    SD = sd(Score)<br>  )<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>6. Advantages of Descriptive Statistics<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Provides quick insights into the dataset<\/li>\n\n\n\n<li>Helps detect patterns, trends, and anomalies<\/li>\n\n\n\n<li>Forms the basis for inferential statistics<\/li>\n\n\n\n<li>Simplifies decision-making based on data summaries<\/li>\n<\/ul>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1775043033576\"><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\">Descriptive statistics are the foundation of data analysis in R. By calculating measures of central tendency, dispersion, quantiles, and frequencies, you can summarize large datasets effectively. Tools like <code>summary()<\/code>, <code>table()<\/code>, and <code>dplyr::summarise()<\/code> make it easier to explore and understand data before further analysis.<\/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) > Statistics with R > Descriptive Statistics<\/span><\/span><\/div>","protected":false},"menu_order":21,"template":"","class_list":["post-44","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>Descriptive Statistics - Analyze Deep. Visualize Better. Build with R.<\/title>\n<meta name=\"description\" content=\"Learn how to calculate descriptive statistics in R including mean, median, mode, variance, and standard deviation with examples.\" \/>\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=\"Descriptive Statistics - Analyze Deep. Visualize Better. Build with R.\" \/>\n<meta property=\"og:description\" content=\"Learn how to calculate descriptive statistics in R including mean, median, mode, variance, and standard deviation with examples.\" \/>\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-01T11:33:57+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\\\/descriptive-statistics\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Descriptive Statistics - Analyze Deep. Visualize Better. Build with R.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/#website\"},\"datePublished\":\"2026-03-03T09:35:54+00:00\",\"dateModified\":\"2026-04-01T11:33:57+00:00\",\"description\":\"Learn how to calculate descriptive statistics in R including mean, median, mode, variance, and standard deviation with examples.\",\"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) > Statistics with R > Descriptive Statistics\"}]},{\"@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":"Descriptive Statistics - Analyze Deep. Visualize Better. Build with R.","description":"Learn how to calculate descriptive statistics in R including mean, median, mode, variance, and standard deviation with examples.","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":"Descriptive Statistics - Analyze Deep. Visualize Better. Build with R.","og_description":"Learn how to calculate descriptive statistics in R including mean, median, mode, variance, and standard deviation with examples.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Analyze Deep. Visualize Better. Build with R.","article_modified_time":"2026-04-01T11:33:57+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\/descriptive-statistics\/","url":"https:\/\/gigz.pk\/","name":"Descriptive Statistics - Analyze Deep. Visualize Better. Build with R.","isPartOf":{"@id":"https:\/\/gigz.pk\/r\/#website"},"datePublished":"2026-03-03T09:35:54+00:00","dateModified":"2026-04-01T11:33:57+00:00","description":"Learn how to calculate descriptive statistics in R including mean, median, mode, variance, and standard deviation with examples.","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) > Statistics with R > Descriptive Statistics"}]},{"@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\/44","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=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}