<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/exploratory-data-analysis-in-r-introduction/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.datascienceheroes.com/exploratory-data-analysis-in-r-intro/"> R - Data Science Heroes Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div><img alt="Exploratory Data Analysis in R (introduction)" src="https://i2.wp.com/blog.datascienceheroes.com/content/images/2018/07/main_img.png?w=456&ssl=1" data-recalc-dims="1">
<p>Hi there!</p>
<p>tl;dr: Exploratory data analysis (<strong>EDA</strong>) the very first step in a data project. We will create a code-template to achieve this with one function.</p>
<h2>Introduction</h2>
<p>EDA consists of univariate (1-variable) and bivariate (2-variables) analysis.<br>
In this post we will review some functions that lead us to the analysis of the first case.</p>
<ul>
<li>Step 1 – First approach to data</li>
<li>Step 2 – Analyzing categorical variables</li>
<li>Step 3 – Analyzing numerical variables</li>
<li>Step 4 – Analyzing numerical and categorical at the same time</li>
</ul>
<p>Covering some key points in a basic EDA:</p>
<ul>
<li>Data types</li>
<li>Outliers</li>
<li>Missing values</li>
<li>Distributions (numerically and graphically) for both, numerical and categorical variables.</li>
</ul>
<h3>Type of analysis results</h3>
<p>They can be two: informative or operative.</p>
<p>Informative – For example plots, or any long variable summary. We cannot filter data from it, but give us a lot of information at once. Most used on the <strong>EDA</strong> stage.</p>
<p>Operative – The results can be used to take an action directly on the data workflow (for example, selecting any variables whose percentage of missing values are below 20%). Most used in the <strong>Data Preparation</strong> stage.</p>
<h3>Setting-up</h3>
<p>Uncoment in case you don’t have any of these libraries:</p>
<pre><code># install.packages(&quot;tidyverse&quot;)
# install.packages(&quot;funModeling&quot;)
# install.packages(&quot;Hmisc&quot;)
</code></pre>
<p>A newer version of <code>funModeling</code> has been released on Ago-1, please update <img alt="😉" src="https://s.w.org/images/core/emoji/2.4/72x72/1f609.png" class="wp-smiley"></p>
<p>Now load the needed libraries…</p>
<pre><code>library(funModeling) 
library(tidyverse) 
library(Hmisc)
</code></pre>
<h3>tl;dr (code)</h3>
<p>Run all the functions in this post in one-shot with the following function:</p>
<pre><code>basic_eda &lt;- function(data)
{
  glimpse(data)
  df_status(data)
  freq(data) 
  profiling_num(data)
  plot_num(data)
  describe(data)
}
</code></pre>
<p>Replace <code>data</code> with <em>your</em> data, and that’s it!:</p>
<p><code>basic_eda(my_amazing_data)</code></p>
<hr>
<p><strong>Creating the data for this example</strong></p>
<p>Using the <code>heart_disease</code> data (from <code>funModeling</code> package). We will take only 4 variables for legibility.</p>
<pre><code>data=heart_disease %>% select(age, max_heart_rate, thal, has_heart_disease)
</code></pre>
<h2>Step 1 – First approach to data</h2>
<p>Number of observations (rows) and variables, and a <code>head</code> of the first cases.</p>
<pre><code>glimpse(data)
</code></pre>
<pre><code>## Observations: 303
## Variables: 4
## $ age               </code></pre></div>