<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/comparing-dataframes-in-r-using-comparedf/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://alexsanjoseph.github.io/r/2018/10/03/comparing-dataframes-in-r-using-comparedf"> Alex's Data Science Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong>NOTE: This is a repost of an article that was first published in 2016</strong></p>
<h1>Introduction</h1>
<p>Every so often while doing data analysis, I have come across a situation where I have<br>
two datasets, which have the same structure but with small differences in the actual<br>
data between the two. For example:</p>
<ul>
<li>Variation of a dataset across different time periods for the same grouping</li>
<li>Variation of values for different algorithms, etc.</li>
</ul>
<p>In the above cases, I want to easily identify what has changed across the two data.frames,<br>
how much has changed, and also hopefully to get a quick summary of the extent of change. There are<br>
packages like the <code>compare</code> package on R, which have focused more on the structure of<br>
the data frame and lesser on the data itself. I was not able to easily identify and<br>
isolate what has changed in the data itself. So I decided to write one for myself. That is<br>
what <code>compareDF</code> package is all about.</p>
<h1>Usage</h1>
<p>The package has a single function, <code>compare_df</code>. It takes in two data frames, and one or<br>
more grouping variables and does a comparison between the the two. In addition you can<br>
specify columns to ignore, decide how many rows of changes to be displayed in the case<br>
of the HTML output, and decide what tolerance you want to provide to detect change.</p>
<h1>Basic Example</h1>
<p>Let’s take the example of a teacher who wants to compare the marks and grades of students across<br>
two years, 2010 and 2011. The data is stored in tabular format.</p>
<div>
<div>
<pre><code><span>load</span><span>(</span><span>&quot;../../compareDF/data/results_2010.rda&quot;</span><span>)</span><span>
</span><span>load</span><span>(</span><span>&quot;../../compareDF/data/results_2011.rda&quot;</span><span>)</span><span>
</span><span>print</span><span>(</span><span>results_2010</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>##    Division Student Maths Physics Chem Discipline PE Art
## 1         A   Isaac    90      84   91          B  B  34
## 2         A  Akshay    85      92   91          B  B  36
## 3         A Vishwas    93      93   92          A  B  21
## 4         A   Rohit    95      92   71          C  B  37
## 5         A    Venu    99      92   82          A  E  78
## 6         A  Ananth    99      81   91          B  A  24
## 7         B    Jojy    67      92   81          B  A  27
## 8         B   Bulla    84      73   81          C  A  68
## 9         B   Katti    90      95   99          C  B  49
## 10        B Dhakkan    78      96   71          C  C  39
## 11        B   Macho    90      82   81         A+  D  30
## 12        B  Mugger    95      71   94          A  C  26
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>print</span><span>(</span><span>results_2011</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>##    Division Student Maths Physics Chem Discipline PE Art
## 1         A   Isaac    90      84   91          A  B  34
## 2         A  Akshay    85      92   91          A  B  36
## 3         A Vishwas    82      93   92          B  B  21
## 4         A   Rohit    94      92   71          D  B  37
## 5         A    Venu   100      92   82          A  E  78
## 6         A  Ananth    78      81   91          B  A  24
## 7         B    Jojy    99      92   81          B  A  27
## 8         B   Bulla    97      73   81          C  A  68
## 9         B   Katti    78      95   99          C  B  49
## 10        B   Rohit    79      96   71          C  C  39
## 11        B   Macho    90      82   81         A+  D  30
## 12        B  Vikram    99      79   98          A  B  99
## 13        B DIkChik    91      71   84          E  C  99
</code></pre>
</div>
</div>
<p>The data shows the performance of students in two divisions, A and B for two years. Some subjects<br>
like <em>Maths, Physics, Chemistry and Art</em> are given scores while others like <em>Discipline and PE</em> are<br>
given grades.</p>
<p>It is possible that there are students of the same name in two divisions, for example, there is<br>
a <em>Rohit</em> in both the divisions in 2011.</p>
<p>It is also possible that some students have dropped out, or added new across the two years.<br>
Eg: – <em>Mugger and Dhakkan</em> dropped out while <em>Vikram and Dikchik</em> where added in the Division B</p>
<p>The package allows a user to quickly identify these changes.</p>
<h2>Basic Comparison</h2>
<p>Now let’s compare the performance of the students across the years. The grouping variables are the<br>
<em>Student</em> column. We will ignore the <em>Division</em> column and assume that the student names are unique<br>
across divisions. In this sub-example, if a student appears in two divisions, he/she has studied in both<br>
of them.</p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>compareDF</span><span>)</span><span>
</span><span>ctable_student</span><span> </span><span>=</span><span> </span><span>compare_df</span><span>(</span><span>results_2011</span><span>,</span><span> </span><span>results_2010</span><span>,</span><span> </span><span>c</span><span>(</span><span>&quot;Student&quot;</span><span>))</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Creating comparison table...
</code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Loading required namespace: htmlTable
</code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Creating HTML table for first 100 rows
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>ctable_student</span><span>$</span><span>comparison_df</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>##    Student chng_type Division Maths Physics Chem Discipline PE Art
## 1   Akshay         +        A    85      92   91          A  B  36
## 2   Akshay         -        A    85      92   91          B  B  36
## 3   Ananth         +        A    78      81   91          B  A  24
## 4   Ananth         -        A    99      81   91          B  A  24
## 5    Bulla         +        B    97      73   81          C  A  68
## 6    Bulla         -        B    84      73   81          C  A  68
## 7  Dhakkan         -        B    78      96   71          C  C  39
## 8    Isaac         +        A    90      84   91          A  B  34
## 9    Isaac         -        A    90      84   91          B  B  34
## 10    Jojy         +        B    99      92   81          B  A  27
## 11    Jojy         -        B    67      92   81          B  A  27
## 12   Katti         +        B    78      95   99          C  B  49
## 13   Katti         -        B    90      95   99          C  B  49
## 14  Mugger         -        B    95      71   94          A  C  26
## 15   Rohit         +        A    94      92   71          D  B  37
## 16   Rohit         +        B    79      96   71          C  C  39
## 17   Rohit         -        A    95      92   71          C  B  37
## 18    Venu         +        A   100      92   82          A  E  78
## 19    Venu         -        A    99      92   82          A  E  78
## 20 Vishwas         +        A    82      93   92          B  B  21
## 21 Vishwas         -        A    93      93   92          A  B  21
## 22 DIkChik         +        B    91      71   84          E  C  99
## 23  Vikram         +        B    99      79   98          A  B  99
</code></pre>
</div>
</div>
<p>By default, no columns are excluded from the comparison, so any of the tuple of grouping<br>
variables which are different across the two data frames are shown in the comparison table.<br>
The <code>comparison_df</code> table shows all the rows for which at least one record has changed. Conversely, if<br>
nothing has changed across the two tables, the rows are not displayed. If a new record has been<br>
introduced or a record has been removed, those are displayed as well.</p>
<p>For example, <em>Akshay, Division A</em> has had the exact same scores but has two different grades for <em>Discipline</em> across<br>
the two years so that row is included.</p>
<p>However, <em>Macho, Division B</em> has had the exact same scores in both the years for all subjects, so his data is not<br>
shown in the comparison table.</p>
<h2>HTML Output</h2>
<p>While the comparison table can be quickly summarized in various forms for futher analysis, it is<br>
very difficult to process visually. The <code>html_output</code> provides a way to represent this is a way that is easier<br>
for the numan eye to read. NOTE: You need to install the <code>htmlTable</code> package for the HTML comparison to work.<br>
<em>For the purpose of the readme I am attaching the html as a png because github markdown doesn’t retain styles.</em></p>
<div>
<div>
<pre><code><span>print</span><span>(</span><span>ctable_student</span><span>$</span><span>html_output</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<table>
<thead>
<tr>
<th>Student</th>
<th>chng_type</th>
<th>Division</th>
<th>Maths</th>
<th>Physics</th>
<th>Chem</th>
<th>Discipline</th>
<th>PE</th>
<th>Art</th>
</tr>
</thead>
<tbody>
<tr>
<td>Akshay</td>
<td>+</td>
<td>A</td>
<td>85</td>
<td>92</td>
<td>91</td>
<td>A</td>
<td>B</td>
<td>36</td>
</tr>
<tr>
<td>Akshay</td>
<td>–</td>
<td>A</td>
<td>85</td>
<td>92</td>
<td>91</td>
<td>B</td>
<td>B</td>
<td>36</td>
</tr>
<tr>
<td>Ananth</td>
<td>+</td>
<td>A</td>
<td>78</td>
<td>81</td>
<td>91</td>
<td>B</td>
<td>A</td>
<td>24</td>
</tr>
<tr>
<td>Ananth</td>
<td>–</td>
<td>A</td>
<td>99</td>
<td>81</td>
<td>91</td>
<td>B</td>
<td>A</td>
<td>24</td>
</tr>
<tr>
<td>Bulla</td>
<td>+</td>
<td>B</td>
<td>97</td>
<td>73</td>
<td>81</td>
<td>C</td>
<td>A</td>
<td>68</td>
</tr>
<tr>
<td>Bulla</td>
<td>–</td>
<td>B</td>
<td>84</td>
<td>73</td>
<td>81</td>
<td>C</td>
<td>A</td>
<td>68</td>
</tr>
<tr>
<td>Dhakkan</td>
<td>–</td>
<td>B</td>
<td>78</td>
<td>96</td>
<td>71</td>
<td>C</td>
<td>C</td>
<td>39</td>
</tr>
<tr>
<td>Isaac</td>
<td>+</td>
<td>A</td>
<td>90</td>
<td>84</td>
<td>91</td>
<td>A</td>
<td>B</td>
<td>34</td>
</tr>
<tr>
<td>Isaac</td>
<td>–</td>
<td>A</td>
<td>90</td>
<td>84</td>
<td>91</td>
<td>B</td>
<td>B</td>
<td>34</td>
</tr>
<tr>
<td>Jojy</td>
<td>+</td>
<td>B</td>
<td>99</td>
<td>92</td>
<td>81</td>
<td>B</td>
<td>A</td>
<td>27</td>
</tr>
<tr>
<td>Jojy</td>
<td>–</td>
<td>B</td>
<td>67</td>
<td>92</td>
<td>81</td>
<td>B</td>
<td>A</td>
<td>27</td>
</tr>
<tr>
<td>Katti</td>
<td>+</td>
<td>B</td>
<td>78</td>
<td>95</td>
<td>99</td>
<td>C</td>
<td>B</td>
<td>49</td>
</tr>
<tr>
<td>Katti</td>
<td>–</td>
<td>B</td>
<td>90</td>
<td>95</td>
<td>99</td>
<td>C</td>
<td>B</td>
<td>49</td>
</tr>
<tr>
<td>Mugger</td>
<td>–</td>
<td>B</td>
<td>95</td>
<td>71</td>
<td>94</td>
<td>A</td>
<td>C</td>
<td>26</td>
</tr>
<tr>
<td>Rohit</td>
<td>+</td>
<td>A</td>
<td>94</td>
<td>92</td>
<td>71</td>
<td>D</td>
<td>B</td>
<td>37</td>
</tr>
<tr>
<td>Rohit</td>
<td>+</td>
<td>B</td>
<td>79</td>
<td>96</td>
<td>71</td>
<td>C</td>
<td>C</td>
<td>39</td>
</tr>
<tr>
<td>Rohit</td>
<td>–</td>
<td>A</td>
<td>95</td>
<td>92</td>
<td>71</td>
<td>C</td>
<td>B</td>
<td>37</td>
</tr>
<tr>
<td>Venu</td>
<td>+</td>
<td>A</td>
<td>100</td>
<td>92</td>
<td>82</td>
<td>A</td>
<td>E</td>
<td>78</td>
</tr>
<tr>
<td>Venu</td>
<td>–</td>
<td>A</td>
<td>99</td>
<td>92</td>
<td>82</td>
<td>A</td>
<td>E</td>
<td>78</td>
</tr>
<tr>
<td>Vishwas</td>
<td>+</td>
<td>A</td>
<td>82</td>
<td>93</td>
<td>92</td>
<td>B</td>
<td>B</td>
<td>21</td>
</tr>
<tr>
<td>Vishwas</td>
<td>–</td>
<td>A</td>
<td>93</td>
<td>93</td>
<td>92</td>
<td>A</td>
<td>B</td>
<td>21</td>
</tr>
<tr>
<td>DIkChik</td>
<td>+</td>
<td>B</td>
<td>91</td>
<td>71</td>
<td>84</td>
<td>E</td>
<td>C</td>
<td>99</td>
</tr>
<tr>
<td>Vikram</td>
<td>+</td>
<td>B</td>
<td>99</td>
<td>79</td>
<td>98</td>
<td>A</td>
<td>B</td>
<td>99</td>
</tr>
</tbody>
</table>
<p>Now it is very easy to see recognize what has changed. A single cell is colored<br>
if it has changed across the two datasets. The value of the cell in the older dataset<br>
is colored red and the value of the cell in the newer dataset is colored green. Cells<br>
that haven’t changed across the two datasets are colored grey.</p>
<p>If a new row was introduced, the Row group names (and all the other columns for that row as well )<br>
are colored in Green. Similarly, a row group name (and the other columns in that row) are<br>
colored red if a row was removed.</p>
<p>For Example, <em>Akshay</em>, <em>Ananth</em> and <em>Bulla</em> has had changes in<br>
scores, which are in <em>Discipline</em>, <em>Maths</em>, and <em>Maths</em> respectively.<br>
<em>Dhakkan</em> and <em>Mugger</em> have dropped out of the dataset from 2010 and the all the columns for the rows are shown<br>
in red, which <em>DikChik</em> and <em>Vikram</em> have joined new in the data set and all the columns for the rows are in green.</p>
<p>The same data is represented in tabular form (for further analysis, if necessary) in the<br>
<code>comparison_table_diff</code> object</p>
<div>
<div>
<pre><code><span>ctable_student</span><span>$</span><span>comparison_table_diff</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>##    Student chng_type Division Maths Physics Chem Discipline PE Art
## 1        .         +        .     .       .    .          +  .   .
## 2        .         -        .     .       .    .          -  .   .
## 3        .         +        .     +       .    .          .  .   .
## 4        .         -        .     -       .    .          .  .   .
## 5        .         +        .     +       .    .          .  .   .
## 6        .         -        .     -       .    .          .  .   .
## 7        -         -        -     -       -    -          -  -   -
## 8        .         +        .     .       .    .          +  .   .
## 9        .         -        .     .       .    .          -  .   .
## 10       .         +        .     +       .    .          .  .   .
## 11       .         -        .     -       .    .          .  .   .
## 12       .         +        .     +       .    .          .  .   .
## 13       .         -        .     -       .    .          .  .   .
## 14       -         -        -     -       -    -          -  -   -
## 15       .         +        +     +       +    .          +  +   +
## 16       .         +        +     +       +    .          +  +   +
## 17       .         -        -     -       -    .          -  -   -
## 18       .         +        .     +       .    .          .  .   .
## 19       .         -        .     -       .    .          .  .   .
## 20       .         +        .     +       .    .          +  .   .
## 21       .         -        .     -       .    .          -  .   .
## 22       +         +        +     +       +    +          +  +   +
## 23       +         +        +     +       +    +          +  +   +
</code></pre>
</div>
</div>
<h2>Change Count and Summary</h2>
<p>You can get an details of what has changed for each group using<br>
the <code>change_count</code> object in the output. A summary<br>
of the same is provided in the <code>change_summary</code> object.</p>
<div>
<div>
<pre><code><span>ctable_student</span><span>$</span><span>change_count</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Source: local data frame [13 x 4]
##
##    Student changes additions removals
##     (fctr)   (dbl)     (dbl)    (dbl)
## 1   Akshay       1         0        0
## 2   Ananth       1         0        0
## 3    Bulla       1         0        0
## 4  Dhakkan       0         1        0
## 5    Isaac       1         0        0
## 6     Jojy       1         0        0
## 7    Katti       1         0        0
## 8   Mugger       0         1        0
## 9    Rohit       1         0        1
## 10    Venu       1         0        0
## 11 Vishwas       1         0        0
## 12 DIkChik       0         0        1
## 13  Vikram       0         0        1
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>ctable_student</span><span>$</span><span>change_summary</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>##   old_obs   new_obs   changes additions  removals
##        12        13         9         2         3
</code></pre>
</div>
</div>
<h2>Grouping Multiple Columns</h2>
<p>We can also group_multiple columns into the grouping variable</p>
<div>
<div>
<pre><code><span>ctable_student_div</span><span> </span><span>=</span><span> </span><span>compare_df</span><span>(</span><span>results_2011</span><span>,</span><span> </span><span>results_2010</span><span>,</span><span> </span><span>c</span><span>(</span><span>&quot;Division&quot;</span><span>,</span><span> </span><span>&quot;Student&quot;</span><span>))</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Grouping grouping columns
</code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Creating comparison table...
</code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Creating HTML table for first 100 rows
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>ctable_student_div</span><span>$</span><span>html_output</span><span>
</span></code></pre>
</div>
</div>
<table>
<thead>
<tr>
<th>grp</th>
<th>chng_type</th>
<th>Division</th>
<th>Student</th>
<th>Maths</th>
<th>Physics</th>
<th>Chem</th>
<th>Discipline</th>
<th>PE</th>
<th>Art</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>+</td>
<td>A</td>
<td>Akshay</td>
<td>85</td>
<td>92</td>
<td>91</td>
<td>A</td>
<td>B</td>
<td>36</td>
</tr>
<tr>
<td>1</td>
<td>–</td>
<td>A</td>
<td>Akshay</td>
<td>85</td>
<td>92</td>
<td>91</td>
<td>B</td>
<td>B</td>
<td>36</td>
</tr>
<tr>
<td>2</td>
<td>+</td>
<td>A</td>
<td>Ananth</td>
<td>78</td>
<td>81</td>
<td>91</td>
<td>B</td>
<td>A</td>
<td>24</td>
</tr>
<tr>
<td>2</td>
<td>–</td>
<td>A</td>
<td>Ananth</td>
<td>99</td>
<td>81</td>
<td>91</td>
<td>B</td>
<td>A</td>
<td>24</td>
</tr>
<tr>
<td>3</td>
<td>+</td>
<td>A</td>
<td>Isaac</td>
<td>90</td>
<td>84</td>
<td>91</td>
<td>A</td>
<td>B</td>
<td>34</td>
</tr>
<tr>
<td>3</td>
<td>–</td>
<td>A</td>
<td>Isaac</td>
<td>90</td>
<td>84</td>
<td>91</td>
<td>B</td>
<td>B</td>
<td>34</td>
</tr>
<tr>
<td>4</td>
<td>+</td>
<td>A</td>
<td>Rohit</td>
<td>94</td>
<td>92</td>
<td>71</td>
<td>D</td>
<td>B</td>
<td>37</td>
</tr>
<tr>
<td>4</td>
<td>–</td>
<td>A</td>
<td>Rohit</td>
<td>95</td>
<td>92</td>
<td>71</td>
<td>C</td>
<td>B</td>
<td>37</td>
</tr>
<tr>
<td>5</td>
<td>+</td>
<td>A</td>
<td>Venu</td>
<td>100</td>
<td>92</td>
<td>82</td>
<td>A</td>
<td>E</td>
<td>78</td>
</tr>
<tr>
<td>5</td>
<td>–</td>
<td>A</td>
<td>Venu</td>
<td>99</td>
<td>92</td>
<td>82</td>
<td>A</td>
<td>E</td>
<td>78</td>
</tr>
<tr>
<td>6</td>
<td>+</td>
<td>A</td>
<td>Vishwas</td>
<td>82</td>
<td>93</td>
<td>92</td>
<td>B</td>
<td>B</td>
<td>21</td>
</tr>
<tr>
<td>6</td>
<td>–</td>
<td>A</td>
<td>Vishwas</td>
<td>93</td>
<td>93</td>
<td>92</td>
<td>A</td>
<td>B</td>
<td>21</td>
</tr>
<tr>
<td>7</td>
<td>+</td>
<td>B</td>
<td>Bulla</td>
<td>97</td>
<td>73</td>
<td>81</td>
<td>C</td>
<td>A</td>
<td>68</td>
</tr>
<tr>
<td>7</td>
<td>–</td>
<td>B</td>
<td>Bulla</td>
<td>84</td>
<td>73</td>
<td>81</td>
<td>C</td>
<td>A</td>
<td>68</td>
</tr>
<tr>
<td>8</td>
<td>+</td>
<td>B</td>
<td>DIkChik</td>
<td>91</td>
<td>71</td>
<td>84</td>
<td>E</td>
<td>C</td>
<td>99</td>
</tr>
<tr>
<td>9</td>
<td>+</td>
<td>B</td>
<td>Jojy</td>
<td>99</td>
<td>92</td>
<td>81</td>
<td>B</td>
<td>A</td>
<td>27</td>
</tr>
<tr>
<td>9</td>
<td>–</td>
<td>B</td>
<td>Jojy</td>
<td>67</td>
<td>92</td>
<td>81</td>
<td>B</td>
<td>A</td>
<td>27</td>
</tr>
<tr>
<td>10</td>
<td>+</td>
<td>B</td>
<td>Katti</td>
<td>78</td>
<td>95</td>
<td>99</td>
<td>C</td>
<td>B</td>
<td>49</td>
</tr>
<tr>
<td>10</td>
<td>–</td>
<td>B</td>
<td>Katti</td>
<td>90</td>
<td>95</td>
<td>99</td>
<td>C</td>
<td>B</td>
<td>49</td>
</tr>
<tr>
<td>12</td>
<td>+</td>
<td>B</td>
<td>Rohit</td>
<td>79</td>
<td>96</td>
<td>71</td>
<td>C</td>
<td>C</td>
<td>39</td>
</tr>
<tr>
<td>13</td>
<td>+</td>
<td>B</td>
<td>Vikram</td>
<td>99</td>
<td>79</td>
<td>98</td>
<td>A</td>
<td>B</td>
<td>99</td>
</tr>
<tr>
<td>14</td>
<td>–</td>
<td>B</td>
<td>Dhakkan</td>
<td>78</td>
<td>96</td>
<td>71</td>
<td>C</td>
<td>C</td>
<td>39</td>
</tr>
<tr>
<td>15</td>
<td>–</td>
<td>B</td>
<td>Mugger</td>
<td>95</td>
<td>71</td>
<td>94</td>
<td>A</td>
<td>C</td>
<td>26</td>
</tr>
</tbody>
</table>
<p>Now <em>Rohits</em> in each individual division are considered as belonging to separate<br>
groups and compared accordingly. All the other summaries also change appropriately.</p>
<h2>Excluding certain Columns</h2>
<p>You can ignore certain columns using the <em>exclude</em> parameter. The fields that have to be<br>
excluded can be given as a character vector. (This is a convenience function to deal with<br>
the case where some columns are not included)</p>
<h2>Limiting HTML size</h2>
<p>For dataframes which have a large amount of differences in them, generating HTML might take<br>
a long time and crash your system. So the maximum diff size for the HTML (and for the HTML<br>
visualization only) is capped at 100 by default. If you want to see more difference, you can change<br>
the <code>limit_html</code> parameter appropriately. NOTE: This is only of the HTML output which is used for visual<br>
checking. The main comparison data frame and the summaries ALWAYS include data from all the rows.</p>
<h2>Tolerance</h2>
<p>It is possible that you’d like numbers very close to each other to be ignored. For example,<br>
if the marks of a student vary by less that 5% across the years, it could be due to random<br>
error and not any real performance indictaor. In such a case, you would want to give a tolerance<br>
parameter. For this case, giving a tolerance of <code>0.05</code> would ignore all the changes that are<br>
less than 5% apart from the lower value.</p>
<div>
<div>
<pre><code><span>ctable_student_div</span><span> </span><span>=</span><span> </span><span>compare_df</span><span>(</span><span>results_2011</span><span>,</span><span> </span><span>results_2010</span><span>,</span><span> </span><span>c</span><span>(</span><span>&quot;Division&quot;</span><span>,</span><span> </span><span>&quot;Student&quot;</span><span>),</span><span> </span><span>tolerance</span><span> </span><span>=</span><span> </span><span>0.05</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Grouping grouping columns
</code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Creating comparison table...
</code></pre>
</div>
</div>
<div>
<div>
<pre><code>## Creating HTML table for first 100 rows
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>ctable_student_div</span><span>$</span><span>html_output</span><span>
</span></code></pre>
</div>
</div>
<table>
<thead>
<tr>
<th>grp</th>
<th>chng_type</th>
<th>Division</th>
<th>Student</th>
<th>Maths</th>
<th>Physics</th>
<th>Chem</th>
<th>Discipline</th>
<th>PE</th>
<th>Art</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>+</td>
<td>A</td>
<td>Akshay</td>
<td>85</td>
<td>92</td>
<td>91</td>
<td>A</td>
<td>B</td>
<td>36</td>
</tr>
<tr>
<td>1</td>
<td>–</td>
<td>A</td>
<td>Akshay</td>
<td>85</td>
<td>92</td>
<td>91</td>
<td>B</td>
<td>B</td>
<td>36</td>
</tr>
<tr>
<td>2</td>
<td>+</td>
<td>A</td>
<td>Ananth</td>
<td>78</td>
<td>81</td>
<td>91</td>
<td>B</td>
<td>A</td>
<td>24</td>
</tr>
<tr>
<td>2</td>
<td>–</td>
<td>A</td>
<td>Ananth</td>
<td>99</td>
<td>81</td>
<td>91</td>
<td>B</td>
<td>A</td>
<td>24</td>
</tr>
<tr>
<td>3</td>
<td>+</td>
<td>A</td>
<td>Isaac</td>
<td>90</td>
<td>84</td>
<td>91</td>
<td>A</td>
<td>B</td>
<td>34</td>
</tr>
<tr>
<td>3</td>
<td>–</td>
<td>A</td>
<td>Isaac</td>
<td>90</td>
<td>84</td>
<td>91</td>
<td>B</td>
<td>B</td>
<td>34</td>
</tr>
<tr>
<td>4</td>
<td>+</td>
<td>A</td>
<td>Rohit</td>
<td>94</td>
<td>92</td>
<td>71</td>
<td>D</td>
<td>B</td>
<td>37</td>
</tr>
<tr>
<td>4</td>
<td>–</td>
<td>A</td>
<td>Rohit</td>
<td>95</td>
<td>92</td>
<td>71</td>
<td>C</td>
<td>B</td>
<td>37</td>
</tr>
<tr>
<td>6</td>
<td>+</td>
<td>A</td>
<td>Vishwas</td>
<td>82</td>
<td>93</td>
<td>92</td>
<td>B</td>
<td>B</td>
<td>21</td>
</tr>
<tr>
<td>6</td>
<td>–</td>
<td>A</td>
<td>Vishwas</td>
<td>93</td>
<td>93</td>
<td>92</td>
<td>A</td>
<td>B</td>
<td>21</td>
</tr>
<tr>
<td>7</td>
<td>+</td>
<td>B</td>
<td>Bulla</td>
<td>97</td>
<td>73</td>
<td>81</td>
<td>C</td>
<td>A</td>
<td>68</td>
</tr>
<tr>
<td>7</td>
<td>–</td>
<td>B</td>
<td>Bulla</td>
<td>84</td>
<td>73</td>
<td>81</td>
<td>C</td>
<td>A</td>
<td>68</td>
</tr>
<tr>
<td>8</td>
<td>+</td>
<td>B</td>
<td>DIkChik</td>
<td>91</td>
<td>71</td>
<td>84</td>
<td>E</td>
<td>C</td>
<td>99</td>
</tr>
<tr>
<td>9</td>
<td>+</td>
<td>B</td>
<td>Jojy</td>
<td>99</td>
<td>92</td>
<td>81</td>
<td>B</td>
<td>A</td>
<td>27</td>
</tr>
<tr>
<td>9</td>
<td>–</td>
<td>B</td>
<td>Jojy</td>
<td>67</td>
<td>92</td>
<td>81</td>
<td>B</td>
<td>A</td>
<td>27</td>
</tr>
<tr>
<td>10</td>
<td>+</td>
<td>B</td>
<td>Katti</td>
<td>78</td>
<td>95</td>
<td>99</td>
<td>C</td>
<td>B</td>
<td>49</td>
</tr>
<tr>
<td>10</td>
<td>–</td>
<td>B</td>
<td>Katti</td>
<td>90</td>
<td>95</td>
<td>99</td>
<td>C</td>
<td>B</td>
<td>49</td>
</tr>
<tr>
<td>12</td>
<td>+</td>
<td>B</td>
<td>Rohit</td>
<td>79</td>
<td>96</td>
<td>71</td>
<td>C</td>
<td>C</td>
<td>39</td>
</tr>
<tr>
<td>13</td>
<td>+</td>
<td>B</td>
<td>Vikram</td>
<td>99</td>
<td>79</td>
<td>98</td>
<td>A</td>
<td>B</td>
<td>99</td>
</tr>
<tr>
<td>14</td>
<td>–</td>
<td>B</td>
<td>Dhakkan</td>
<td>78</td>
<td>96</td>
<td>71</td>
<td>C</td>
<td>C</td>
<td>39</td>
</tr>
<tr>
<td>15</td>
<td>–</td>
<td>B</td>
<td>Mugger</td>
<td>95</td>
<td>71</td>
<td>94</td>
<td>A</td>
<td>C</td>
<td>26</td>
</tr>
</tbody>
</table>
<p><em>Venu from division A</em> who had a score change from 100 to 99 is no longer present in the<br>
diff calculation or in the output</p>
<p>Naturally, tolerance has no meaning for non-numeric values.</p>
<h2>Acknowledgements</h2>
<p>I’d like to thank System Insights Inc. for all the things that I have learned while working<br>
there which I have used one way or the other in this package. Special thanks to Nitin for<br>
proofreading the doc and making sure everything made sense.</p>
<p><em>A version of this blog has been published as the README for the <a rel="nofollow" href="https://github.com/alexsanjoseph/compareDF" target="_blank">package</a>.</em></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://alexsanjoseph.github.io/r/2018/10/03/comparing-dataframes-in-r-using-comparedf"> Alex's Data Science Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/hYf8-_vbruE" height="1"></a></div>