{"id":77911,"date":"2020-04-02T16:20:45","date_gmt":"2020-04-02T10:50:45","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=77911"},"modified":"2020-04-02T16:20:45","modified_gmt":"2020-04-02T10:50:45","slug":"r-descriptive-statistics","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/","title":{"rendered":"Descriptive Statistics in R &#8211; Functions to perform statistic measures"},"content":{"rendered":"<p><strong>In this article of TechVidvan\u2019s R tutorial series, learn about descriptive statistics in R, what are its uses and how we can perform it in R. <\/strong><\/p>\n<p>We will begin this lesson by learning what descriptive statistics are. We shall then continue on with some basic functions of R that are very useful when it comes to descriptive statistics. Also, learn what data structures these functions process and what function do we have to use for different data structures.<\/p>\n<p>So, without any further ado. Let\u2019s get started!<\/p>\n<h3>What is Descriptive Statistics?<\/h3>\n<p>Descriptive statistics is the branch of statistics that focuses on <strong>describing<\/strong> and gaining more insight into the data in its present state. It deals with what the data in its <strong>current state<\/strong> means. It makes the data easier to understand and also gives us knowledge about the data which is necessary to perform further analysis. Average measures like mean, median, mode, etc. are a good example of descriptive statistics.<\/p>\n<h2>Descriptive Statistics in R<\/h2>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/descriptive-statistics-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77923\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/descriptive-statistics-in-R.jpg\" alt=\"descriptive statistics in R\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<p>R programming language provides us with lots of simple yet effective functions to perform descriptive statistics and gain more knowledge about our data. Summarizing the data, calculating average measures, finding out cumulative measures, summarizing rows\/columns of data structures, etc. everything is possible with trivial commands. Let\u2019s start simple with the summarizing functions <strong><code>str()<\/code><\/strong> and <strong><code>summary()<\/code><\/strong>.<\/p>\n<h3>Summarizing your Data<\/h3>\n<p>R provides two very simple functions that can instantly summarize our data for us. These are the <strong><code>str()<\/code><\/strong> and the <strong><code>summary()<\/code><\/strong> functions.<\/p>\n<p>Let us begin with the str function. The <strong><code>str()<\/code><\/strong> function takes a single object as an argument and compactly shows us the <strong>structure<\/strong> of the input object. It shows us details like length, data type, names and other specifics about the components of the object. Here is an example of the str function.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">str(mtcars)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/1.descriptive-statistics-in-r-str-function-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77918\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/1.descriptive-statistics-in-r-str-function-1.png\" alt=\"str function - descriptive statistics in r\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<p>The <strong><code>summary()<\/code><\/strong> function also takes a single object as an argument. It then returns the <strong>averages measures<\/strong> like mean, median, minimum, maximum, 1st quantile, 3rd quantile, etc. for each component or variable in the object. Here is an example of the summary function in action.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">summary(mtcars)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/2.descriptive-statistics-in-r-summary-function.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77919\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/2.descriptive-statistics-in-r-summary-function.png\" alt=\"summary function - descriptive statistics in r\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<h3>Getting the Average Measures<\/h3>\n<p>R provides a number of functions that give us different average measures for given data. These average measures include:<\/p>\n<p><strong>Mean:<\/strong> The mean of a given set of numeric or logical values(it may be a vector or a row or column of any other data structure) can be easily found using the <strong><code>mean()<\/code><\/strong> function.<\/p>\n<p><strong>Median:<\/strong> Finding the median of a set of numeric or logical values is also very easy by using the <strong><code>median()<\/code><\/strong> function.<\/p>\n<p><strong>Standard deviation:<\/strong> The standard deviation of a set of numerical values can be found using the <strong><code>sd()<\/code><\/strong> function.<\/p>\n<p><strong>Variance:<\/strong> the <strong><code>var()<\/code><\/strong> function gives us the variance of a set of numeric or logical values.<\/p>\n<p><strong>Median Absolute Variance:<\/strong> The median absolute variance of a set of numeric or logical values can be found by using the <strong><code>mad()<\/code><\/strong> function.<\/p>\n<p><strong>Maximum:<\/strong> In a given set of numeric or logical values, we can use the <strong><code>max()<\/code><\/strong> function to find the maximum or the largest value in the set.<\/p>\n<p><strong>Note:<\/strong> NA is considered to be the largest by the <strong><code>max()<\/code><\/strong> function unless its na.rm argument is set to TRUE.<\/p>\n<p><strong>Minimum:<\/strong> The <strong><code>min()<\/code><\/strong> function is a very handy way to find out the smallest value in a set of numeric values.<\/p>\n<p><strong>Note:<\/strong> Like the <strong><code>max()<\/code><\/strong> function, the min() function considers NA to be the smallest unless na.rm is set to TRUE.<\/p>\n<p><strong>Sum:<\/strong> The sum of a set of numerical values can be found by simply using the <strong><code>sum()<\/code><\/strong> function.<\/p>\n<p><strong>Length:<\/strong> The length or the number of values in a set is given by the <strong><code>length()<\/code><\/strong> function.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">mean(mtcars$mpg)\nmedian(mtcars$mpg)\nsd(mtcars$mpg)\nvar(mtcars$mpg)\nmad(mtcars$mpg)\nmax(mtcars$mpg, na.rm = TRUE)\nmin(mtcars$mpg, na.rm = TRUE)\nsum(mtcars$mpg)\nlength(mtcars$mpg)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/3.descriptive-statistics-in-r-average-measures.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77920\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/3.descriptive-statistics-in-r-average-measures.png\" alt=\"average measures - descriptive statistics in r\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<h3>Cumulative measures in R<\/h3>\n<p>Cumulative measures are statistical measures that are calculated <strong>sequentially<\/strong>. These measures evolve with the data. They provide insight into the <strong>progression and growth<\/strong> of the data. <a href=\"https:\/\/www.r-project.org\/\">R<\/a> provides a few functions that calculate cumulative measures with ease. These functions are<\/p>\n<p><strong>Cumulative sum:<\/strong> The <strong><code>cumsum()<\/code><\/strong> function calculates the cumulative sum of a given vector.<\/p>\n<p><strong>Cumulative max:<\/strong> To find the cumulative maximum value of an input vector, you can use the <strong><code>cummax()<\/code><\/strong> function.<\/p>\n<p><strong>Cumulative min:<\/strong> You can find the cumulative minimum values in a vector by using the <strong><code>cummin()<\/code><\/strong> function.<\/p>\n<p><strong>Cumulative product:<\/strong> Using the <strong><code>comprod()<\/code><\/strong> function, you can find the cumulative product of a vector.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">a &lt;- c(1:9,4,2,4,5:2)\ncumsum(a)\ncummax(a)\ncummin(a)\ncumprod(a)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/4.descriptive-statistics-in-r-cumulative-measures.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77921\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/4.descriptive-statistics-in-r-cumulative-measures.png\" alt=\"cumulative measures - descriptive statistics in r\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<h3>Row and Column Summary Functions in R<\/h3>\n<p>There are certain functions in R that give summary statistics for only <strong>selected rows or columns<\/strong> of data frames or matrices or any other two or more dimensional data structure.<\/p>\n<p>These functions are:<\/p>\n<p><strong>rowMeans:<\/strong> The <strong><code>rowMeans()<\/code><\/strong> function, as the name suggests, returns the mean of a selected row of a data structure.<\/p>\n<p><strong>rowSums:<\/strong> The <strong><code>rowSums()<\/code><\/strong> function finds the sum of a selected row of a data structure.<\/p>\n<p><strong>colMeans:<\/strong> The <strong><code>colMeans()<\/code><\/strong> function returns the mean of a selected column of a data structure.<\/p>\n<p><strong>colSums:<\/strong> The <strong><code>colSums()<\/code><\/strong> function calculate the sum of a selected column of a data structure.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">rowMeans(mtcars[2,])\nrowSums(mtcars[2,])\ncolMeans(mtcars)\ncolSums(mtcars)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/5.descriptive-statistics-in-r-row-and-column-measures.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77922\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/5.descriptive-statistics-in-r-row-and-column-measures.png\" alt=\"row and column measures - descriptive statistics in r\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>Descriptive statistics in R do not concern with the impact of the data. It is merely concerned with the current state of the data. It describes the data and gives more detailed knowledge about the data.<\/p>\n<p>In this R tutorial, we learned what descriptive statistics are and how R functions help us to perform descriptive statistic measures on our data to gain more insight into it.<\/p>\n<p>Now, explore <a href=\"https:\/\/techvidvan.com\/tutorials\/r-string-manipulation\/\"><strong>top 10 String Manipulation functions<\/strong><\/a> to create and modify strings in R.<\/p>\n<p>If you face any difficulty while practicing Descriptive Statistics in R.<\/p>\n<p>Then ask our <strong>TechVidvan<\/strong> team in the comment section.<\/p>\n<p>Keep Practicing!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article of TechVidvan\u2019s R tutorial series, learn about descriptive statistics in R, what are its uses and how we can perform it in R. We will begin this lesson by learning what&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":77923,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1020],"tags":[1477,2265,2266,2267,2268,2269,1484],"class_list":["post-77911","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-descriptive-statistics-in-r","tag-r-cumulative-statistics","tag-r-matrix-object","tag-r-summary-commands","tag-r-summary-statistics","tag-r-summary-statistics-table","tag-summary-statistics-in-r"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Descriptive Statistics in R - Functions to perform statistic measures - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn descriptive statistics in R &amp; explore how R functions can help you to perform descriptive statistic measures on this data to gain more insights in R.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Descriptive Statistics in R - Functions to perform statistic measures - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn descriptive statistics in R &amp; explore how R functions can help you to perform descriptive statistic measures on this data to gain more insights in R.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-02T10:50:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/descriptive-statistics-in-R.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Descriptive Statistics in R - Functions to perform statistic measures - TechVidvan","description":"Learn descriptive statistics in R & explore how R functions can help you to perform descriptive statistic measures on this data to gain more insights in R.","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:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/","og_locale":"en_US","og_type":"article","og_title":"Descriptive Statistics in R - Functions to perform statistic measures - TechVidvan","og_description":"Learn descriptive statistics in R & explore how R functions can help you to perform descriptive statistic measures on this data to gain more insights in R.","og_url":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-04-02T10:50:45+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/descriptive-statistics-in-R.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Descriptive Statistics in R &#8211; Functions to perform statistic measures","datePublished":"2020-04-02T10:50:45+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/"},"wordCount":914,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/descriptive-statistics-in-R.jpg","keywords":["Descriptive Statistics in R","R Cumulative Statistics","R matrix object","R summary commands","R summary statistics","R summary statistics table","summary statistics in R"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/","url":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/","name":"Descriptive Statistics in R - Functions to perform statistic measures - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/descriptive-statistics-in-R.jpg","datePublished":"2020-04-02T10:50:45+00:00","description":"Learn descriptive statistics in R & explore how R functions can help you to perform descriptive statistic measures on this data to gain more insights in R.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/descriptive-statistics-in-R.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/descriptive-statistics-in-R.jpg","width":802,"height":420,"caption":"descriptive statistics in R"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/r-descriptive-statistics\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Descriptive Statistics in R &#8211; Functions to perform statistic measures"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77911","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=77911"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77911\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/77923"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=77911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=77911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=77911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}