<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/rcase4base-sorting-data-with-base-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/"> Jozef's Rblog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<h1>Introduction</h1>
<p>In this post in the <a rel="nofollow" href="http://jozefhajnala.gitlab.io/r/categories/rcase4base/" target="_blank">R:case4base</a> series we will examine sorting (ordering) data in base R. We will learn to sort our data based on one or multiple columns, with ascending or descending order and as always look at alternatives to base R, namely the tidyverse’s dplyr and data.table to show how we can achieve the same results.</p>
<p>It is recommended to first have a look at the <a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r002-data-manipulation/" target="_blank">post on subsetting</a> to understand the concepts underlying the sorting process in more detail.</p>
</div>
<div>
<h1>Contents</h1>
<ol>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#introduction" target="_blank">Introduction</a></li>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#how-to-use-this-article" target="_blank">How to use this article</a></li>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#subsetting-as-a-mechanism-for-sorting-data" target="_blank">Subsetting as a mechanism for sorting data</a></li>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#sorting-data-by-contents-of-a-column" target="_blank">Sorting data by contents of a column</a></li>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#sorting-by-multiple-vectors-with-different-order" target="_blank">Sorting by multiple vectors with different order</a></li>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#alternatives-to-base-r" target="_blank">Alternatives to base R</a>
<ol>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#using-the-tidyverse" target="_blank">Using the tidyverse</a></li>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#using-data.table" target="_blank">Using data.table</a></li>
</ol>
</li>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#quick-benchmarking" target="_blank">Quick benchmarking</a></li>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#tldr---just-want-the-code" target="_blank">TL;DR – Just want the code</a></li>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/#references" target="_blank">References</a></li>
</ol>
</div>
<div>
<h1>How to use this article</h1>
<ol>
<li>This article is best used with an R session opened in a window next to it – you can test and play with the code yourself instantly while reading. Assuming the author did not fail miserably, the code will work as-is even with vanilla R, no packages or setup needed – it is a <code>case4base</code> after all!</li>
<li>If you have no time for reading, you can <a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/post/data/r008-sorting-data.r" target="_blank">click here to get just the code with commentary</a></li>
</ol>
<p>First, let’s read in yearly data on gross disposable income of household in the EU countries into R (<a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/post/data/ESA2010_GDI.csv" target="_blank">click here to download</a>):</p>
<pre><code>gdi &lt;- read.csv(
  stringsAsFactors = FALSE
, url(&quot;https://jozefhajnala.gitlab.io/r/post/data/ESA2010_GDI.csv&quot;)
              )
head(gdi[, 1:6, drop = FALSE])</code></pre>
<pre><code>##          country   Y.1995    Y.1996    Y.1997    Y.1998    Y.1999
## 1          EU 28       NA        NA        NA        NA 5982392.8
## 2   Euro area 19       NA        NA        NA        NA 4393727.3
## 3        Belgium 140734.1  141599.4  145023.2  149705.2  153804.0
## 4       Bulgaria   1036.0    1468.1   12367.4   14921.1   16052.8
## 5 Czech Republic 894042.0 1030001.0 1153966.0 1223783.0 1280040.0
## 6        Denmark 566363.0  578102.0  591416.0  621236.0  614893.0</code></pre>
<p>Please note that the figures in the data provided by Eurostat are presented in millions of euros for euro area countries, euro area and EU aggregates and in millions of national currency otherwise. This makes comparing the results between countries difficult, since one would need to do a proper time-dependent currency conversion and potentially inflation adjustment to get comparable data.</p>
<blockquote>
<p>The goal of the article is therefore not really in presenting these concrete results, but to focus on the technical aspects and usefulness of the presented methods.</p>
</blockquote>
</div>
<div>
<h1>Subsetting as a mechanism for sorting data</h1>
<p>Sorting a data frame is loosely coupled with subsetting. To get the rows of a data frame in order reverse to the current one, we can just subset the rows with an index that goes from the last row to the very first (or safer, zeroth) like so:</p>
<pre><code>gdi_reversed_rows &lt;- gdi[nrow(gdi):0, ]</code></pre>
<p>We can take a very similar approach to reverse order the columns:</p>
<pre><code>gdi_reversed_cols &lt;- gdi[, ncol(gdi):0]</code></pre>
<p>Or both rows and columns at the same time. We also add the <code>drop = FALSE</code> for safety here as we omitted it in the 2 above examples for readability:</p>
<pre><code>gdi_reversed &lt;- gdi[nrow(gdi):0, ncol(gdi):0, drop = FALSE]
head(gdi_reversed)</code></pre>
<pre><code>##     Y.2016  Y.2015    Y.2014    Y.2013    Y.2012    Y.2011    Y.2010
## 35      NA      NA        NA        NA        NA        NA        NA
## 34      NA 1631795 1438281.4 1268729.8 1081744.9  971545.3  807128.5
## 33  458641  447094  449119.3  437596.6  428131.2  420404.9  412363.1
## 32 1627136 1606745 1496128.0 1419380.0 1347970.0 1272065.0 1204442.0
## 31      NA      NA 1055733.5  980494.9  934077.3  872900.3  798916.7
## 30 1330854 1298475 1269177.0 1219699.0 1195227.0 1160813.0 1151812.0
##       Y.2009    Y.2008    Y.2007    Y.2006   Y.2005   Y.2004   Y.2003
## 35        NA        NA        NA        NA       NA       NA       NA
## 34  689431.6        NA        NA        NA       NA       NA       NA
## 33  404446.9  399834.1  389468.0  368868.0 352620.1 341709.9 337742.9
## 32 1150829.0 1105563.0 1021911.0  943515.0 975153.0 894892.0 854026.0
## 31  858678.9  909995.1  827339.5  681058.3 631210.9 536194.9 478645.8
## 30 1101109.0 1080225.0 1063178.0 1005630.0 966175.0 926670.0 893528.0
##      Y.2002   Y.2001   Y.2000   Y.1999   Y.1998   Y.1997   Y.1996   Y.1995
## 35       NA       NA       NA       NA       NA       NA       NA       NA
## 34       NA       NA       NA       NA       NA       NA       NA       NA
## 33 335845.6 336581.4 326269.3 312478.7 303239.5 296324.6 291208.4 287865.4
## 32 800130.0 727228.0 704697.0 660196.0 630865.0 582597.0 549694.0 522981.0
## 31 447572.6 400145.0 369181.0       NA       NA       NA       NA       NA
## 30 857352.0 829908.0 789615.0 737419.0 715396.0 691951.0 656455.0 618959.0
##           country
## 35         Serbia
## 34         Turkey
## 33    Switzerland
## 32         Norway
## 31        Iceland
## 30 United Kingdom</code></pre>
</div>
<div>
<h1>Sorting data by contents of a column</h1>
<p>To order the rows (countries) by GDI in 2016, we use the function <code>order</code>, which finds the permutation that rearranges the values into ascending order and save that order into a variable called <code>rowidx</code>. Then we simply use <code>rowidx</code> to subset the rows of <code>gdi</code> in the order we wanted:</p>
<pre><code>rowidx &lt;- order(gdi[, &quot;Y.2016&quot;])
rowidx</code></pre>
<pre><code>##  [1] 13  8 16 18 17 26 27  4  9 28 24 22  3 21 33 11  6 23 14 30 12 32  7
## [24] 29  5  2  1 10 15 19 20 25 31 34 35</code></pre>
<pre><code>gdi_sorted &lt;- gdi[rowidx, , drop = FALSE]

# We can of course do it in one go:
gdi_sorted &lt;- gdi[order(gdi[, &quot;Y.2016&quot;]), , drop = FALSE]

# Look at the 2 relevant columns of the result 
gdi_sorted[, c(1, 23)]</code></pre>
<pre><code>##           country     Y.2016
## 13        Croatia       0.00
## 8         Estonia   12548.30
## 16         Latvia   15737.79
## 18     Luxembourg   20155.80
## 17      Lithuania   24743.49
## 26       Slovenia   24756.63
## 27       Slovakia   48882.91
## 4        Bulgaria   60237.00
## 9         Ireland   97318.90
## 28        Finland  126590.00
## 24       Portugal  128789.39
## 22        Austria  214980.60
## 3         Belgium  243825.50
## 21    Netherlands  357383.00
## 33    Switzerland  458641.00
## 11          Spain  698701.00
## 6         Denmark 1091542.00
## 23         Poland 1136916.00
## 14          Italy 1142273.40
## 30 United Kingdom 1330854.00
## 12         France 1425435.00
## 32         Norway 1627136.00
## 7         Germany 2019917.00
## 29         Sweden 2402587.00
## 5  Czech Republic 2523229.00
## 2    Euro area 19 6736686.43
## 1           EU 28 9454683.60
## 10         Greece         NA
## 15         Cyprus         NA
## 19        Hungary         NA
## 20          Malta         NA
## 25        Romania         NA
## 31        Iceland         NA
## 34         Turkey         NA
## 35         Serbia         NA</code></pre>
<p>To order in descending order, we can use <code>decreasing = TRUE</code>, to see <code>NA</code>s first we can use <code>na.last = FALSE</code></p>
<pre><code>rowidx &lt;- order(gdi[, &quot;Y.2016&quot;], decreasing = TRUE, na.last = FALSE)
gdi[rowidx, c(1, 23), drop = FALSE]</code></pre>
<pre><code>##           country     Y.2016
## 10         Greece         NA
## 15         Cyprus         NA
## 19        Hungary         NA
## 20          Malta         NA
## 25        Romania         NA
## 31        Iceland         NA
## 34         Turkey         NA
## 35         Serbia         NA
## 1           EU 28 9454683.60
## 2    Euro area 19 6736686.43
## 5  Czech Republic 2523229.00
## 29         Sweden 2402587.00
## 7         Germany 2019917.00
## 32         Norway 1627136.00
## 12         France 1425435.00
## 30 United Kingdom 1330854.00
## 14          Italy 1142273.40
## 23         Poland 1136916.00
## 6         Denmark 1091542.00
## 11          Spain  698701.00
## 33    Switzerland  458641.00
## 21    Netherlands  357383.00
## 3         Belgium  243825.50
## 22        Austria  214980.60
## 24       Portugal  128789.39
## 28        Finland  126590.00
## 9         Ireland   97318.90
## 4        Bulgaria   60237.00
## 27       Slovakia   48882.91
## 26       Slovenia   24756.63
## 17      Lithuania   24743.49
## 18     Luxembourg   20155.80
## 16         Latvia   15737.79
## 8         Estonia   12548.30
## 13        Croatia       0.00</code></pre>
</div>
<div>
<h1>Sorting by multiple vectors with different order</h1>
<p>That looks good, but we may want to order the rows that have <code>NA</code> as GDI in 2016 alphabetically by country (or generalize even further). To use multiple vectors for ordering is also very simple:</p>
<pre><code>rowidx &lt;- order(gdi[, &quot;Y.2016&quot;], gdi[, &quot;country&quot;])
head(gdi[rowidx, c(1, 23), drop = FALSE])</code></pre>
<pre><code>##       country   Y.2016
## 13    Croatia     0.00
## 8     Estonia 12548.30
## 16     Latvia 15737.79
## 18 Luxembourg 20155.80
## 17  Lithuania 24743.49
## 26   Slovenia 24756.63</code></pre>
<p>To order by multiple columns differently, for numeric vectors we can use a simple <code>-</code>, since negated numeric vector will order in reverse order. To order our GDI dataset by GDI in 2016 descending and then by country alphabetically:</p>
<pre><code>rowidx &lt;- order(-gdi[, &quot;Y.2016&quot;], gdi[, &quot;country&quot;])
gdi[rowidx, c(1, 23), drop = FALSE]</code></pre>
<pre><code>##           country     Y.2016
## 1           EU 28 9454683.60
## 2    Euro area 19 6736686.43
## 5  Czech Republic 2523229.00
## 29         Sweden 2402587.00
## 7         Germany 2019917.00
## 32         Norway 1627136.00
## 12         France 1425435.00
## 30 United Kingdom 1330854.00
## 14          Italy 1142273.40
## 23         Poland 1136916.00
## 6         Denmark 1091542.00
## 11          Spain  698701.00
## 33    Switzerland  458641.00
## 21    Netherlands  357383.00
## 3         Belgium  243825.50
## 22        Austria  214980.60
## 24       Portugal  128789.39
## 28        Finland  126590.00
## 9         Ireland   97318.90
## 4        Bulgaria   60237.00
## 27       Slovakia   48882.91
## 26       Slovenia   24756.63
## 17      Lithuania   24743.49
## 18     Luxembourg   20155.80
## 16         Latvia   15737.79
## 8         Estonia   12548.30
## 13        Croatia       0.00
## 15         Cyprus         NA
## 10         Greece         NA
## 19        Hungary         NA
## 31        Iceland         NA
## 20          Malta         NA
## 25        Romania         NA
## 35         Serbia         NA
## 34         Turkey         NA</code></pre>
<p>For non-numeric vectors, we can take advantage of the <code>xtfrm</code> function, which returns a numeric vector which will sort in the same order as the one provided to it. Then we just use <code>-</code> to get a vector that will order in reverse order. To order our GDI dataset by GDI ascending in 2016 and then by country reverse-alphabetically:</p>
<pre><code>rowidx &lt;- order(gdi[, &quot;Y.2016&quot;], -xtfrm(gdi[, &quot;country&quot;]))
gdi[rowidx, c(1, 23), drop = FALSE]</code></pre>
<pre><code>##           country     Y.2016
## 13        Croatia       0.00
## 8         Estonia   12548.30
## 16         Latvia   15737.79
## 18     Luxembourg   20155.80
## 17      Lithuania   24743.49
## 26       Slovenia   24756.63
## 27       Slovakia   48882.91
## 4        Bulgaria   60237.00
## 9         Ireland   97318.90
## 28        Finland  126590.00
## 24       Portugal  128789.39
## 22        Austria  214980.60
## 3         Belgium  243825.50
## 21    Netherlands  357383.00
## 33    Switzerland  458641.00
## 11          Spain  698701.00
## 6         Denmark 1091542.00
## 23         Poland 1136916.00
## 14          Italy 1142273.40
## 30 United Kingdom 1330854.00
## 12         France 1425435.00
## 32         Norway 1627136.00
## 7         Germany 2019917.00
## 29         Sweden 2402587.00
## 5  Czech Republic 2523229.00
## 2    Euro area 19 6736686.43
## 1           EU 28 9454683.60
## 34         Turkey         NA
## 35         Serbia         NA
## 25        Romania         NA
## 20          Malta         NA
## 31        Iceland         NA
## 19        Hungary         NA
## 10         Greece         NA
## 15         Cyprus         NA</code></pre>
</div>
<div>
<h1>Alternatives to base R</h1>
<div>
<h2>Using the tidyverse</h2>
<p>The <code>dplyr</code> package comes with a set of very user-friendly functions that are very easy to use, especially in an interactive setting where we know the column names up front, so we can take advantage of the non-standard evaluation:</p>
<pre><code>library(dplyr)
gdi %>% 
  arrange(Y.2016, desc(country)) %>% 
  select(1, 23)</code></pre>
<pre><code>##           country     Y.2016
## 1         Croatia       0.00
## 2         Estonia   12548.30
## 3          Latvia   15737.79
## 4      Luxembourg   20155.80
## 5       Lithuania   24743.49
## 6        Slovenia   24756.63
## 7        Slovakia   48882.91
## 8        Bulgaria   60237.00
## 9         Ireland   97318.90
## 10        Finland  126590.00
## 11       Portugal  128789.39
## 12        Austria  214980.60
## 13        Belgium  243825.50
## 14    Netherlands  357383.00
## 15    Switzerland  458641.00
## 16          Spain  698701.00
## 17        Denmark 1091542.00
## 18         Poland 1136916.00
## 19          Italy 1142273.40
## 20 United Kingdom 1330854.00
## 21         France 1425435.00
## 22         Norway 1627136.00
## 23        Germany 2019917.00
## 24         Sweden 2402587.00
## 25 Czech Republic 2523229.00
## 26   Euro area 19 6736686.43
## 27          EU 28 9454683.60
## 28         Turkey         NA
## 29         Serbia         NA
## 30        Romania         NA
## 31          Malta         NA
## 32        Iceland         NA
## 33        Hungary         NA
## 34         Greece         NA
## 35         Cyprus         NA</code></pre>
<p>If we need to provide the names of the columns instead, we can use the <code>arrange_at</code>:</p>
<pre><code>gdi %>% 
  arrange_at(&quot;country&quot;, desc) %>%
  arrange_at(&quot;Y.2016&quot;) %>%
  select(1, 23)</code></pre>
<pre><code>##           country     Y.2016
## 1         Croatia       0.00
## 2         Estonia   12548.30
## 3          Latvia   15737.79
## 4      Luxembourg   20155.80
## 5       Lithuania   24743.49
## 6        Slovenia   24756.63
## 7        Slovakia   48882.91
## 8        Bulgaria   60237.00
## 9         Ireland   97318.90
## 10        Finland  126590.00
## 11       Portugal  128789.39
## 12        Austria  214980.60
## 13        Belgium  243825.50
## 14    Netherlands  357383.00
## 15    Switzerland  458641.00
## 16          Spain  698701.00
## 17        Denmark 1091542.00
## 18         Poland 1136916.00
## 19          Italy 1142273.40
## 20 United Kingdom 1330854.00
## 21         France 1425435.00
## 22         Norway 1627136.00
## 23        Germany 2019917.00
## 24         Sweden 2402587.00
## 25 Czech Republic 2523229.00
## 26   Euro area 19 6736686.43
## 27          EU 28 9454683.60
## 28         Turkey         NA
## 29         Serbia         NA
## 30        Romania         NA
## 31          Malta         NA
## 32        Iceland         NA
## 33        Hungary         NA
## 34         Greece         NA
## 35         Cyprus         NA</code></pre>
</div>
<div>
<h2>Using data.table</h2>
<p>There are multiple ways to achieve the desired results with data.table, the one syntactically similar to base R is:</p>
<pre><code>library(data.table)
gdidt &lt;- as.data.table(gdi)
gdidt[order(Y.2016, -country), c(1, 23)]</code></pre>
<pre><code>##            country     Y.2016
##  1:        Croatia       0.00
##  2:        Estonia   12548.30
##  3:         Latvia   15737.79
##  4:     Luxembourg   20155.80
##  5:      Lithuania   24743.49
##  6:       Slovenia   24756.63
##  7:       Slovakia   48882.91
##  8:       Bulgaria   60237.00
##  9:        Ireland   97318.90
## 10:        Finland  126590.00
## 11:       Portugal  128789.39
## 12:        Austria  214980.60
## 13:        Belgium  243825.50
## 14:    Netherlands  357383.00
## 15:    Switzerland  458641.00
## 16:          Spain  698701.00
## 17:        Denmark 1091542.00
## 18:         Poland 1136916.00
## 19:          Italy 1142273.40
## 20: United Kingdom 1330854.00
## 21:         France 1425435.00
## 22:         Norway 1627136.00
## 23:        Germany 2019917.00
## 24:         Sweden 2402587.00
## 25: Czech Republic 2523229.00
## 26:   Euro area 19 6736686.43
## 27:          EU 28 9454683.60
## 28:         Turkey         NA
## 29:         Serbia         NA
## 30:        Romania         NA
## 31:          Malta         NA
## 32:        Iceland         NA
## 33:        Hungary         NA
## 34:         Greece         NA
## 35:         Cyprus         NA
##            country     Y.2016</code></pre>
<p>Another option is to take advantage of the <code>setorderv</code> method provided by data.table. The important distinction is that this will sort the existing data.table in place, changing the source object. The other methods used above leave the source object untouched:</p>
<pre><code># This will sort the gdidt by reference - changing the input object
setorderv(gdidt, c(&quot;Y.2016&quot;, &quot;country&quot;), c(1, -1), na.last = TRUE)
# So we now just subset the (already sorted) gdidt
gdidt[, c(1, 23)]</code></pre>
<pre><code>##            country     Y.2016
##  1:        Croatia       0.00
##  2:        Estonia   12548.30
##  3:         Latvia   15737.79
##  4:     Luxembourg   20155.80
##  5:      Lithuania   24743.49
##  6:       Slovenia   24756.63
##  7:       Slovakia   48882.91
##  8:       Bulgaria   60237.00
##  9:        Ireland   97318.90
## 10:        Finland  126590.00
## 11:       Portugal  128789.39
## 12:        Austria  214980.60
## 13:        Belgium  243825.50
## 14:    Netherlands  357383.00
## 15:    Switzerland  458641.00
## 16:          Spain  698701.00
## 17:        Denmark 1091542.00
## 18:         Poland 1136916.00
## 19:          Italy 1142273.40
## 20: United Kingdom 1330854.00
## 21:         France 1425435.00
## 22:         Norway 1627136.00
## 23:        Germany 2019917.00
## 24:         Sweden 2402587.00
## 25: Czech Republic 2523229.00
## 26:   Euro area 19 6736686.43
## 27:          EU 28 9454683.60
## 28:         Turkey         NA
## 29:         Serbia         NA
## 30:        Romania         NA
## 31:          Malta         NA
## 32:        Iceland         NA
## 33:        Hungary         NA
## 34:         Greece         NA
## 35:         Cyprus         NA
##            country     Y.2016</code></pre>
</div>
</div>
<div>
<h1>Quick benchmarking</h1>
<p>For a quick overview, lets look at a basic benchmark without package loading overhead for each of the mentioned packages. To do the benchmarking, we will use a very slightly modified <code>flights</code> data frame provided by Hadley Wickham’s <a rel="nofollow" href="https://cran.r-project.org/package=nycflights13" target="_blank">nycflights13</a> package.</p>
<p><br>
<br>
</p>
<pre><code>library(data.table)
library(dplyr)
dataurl &lt;- &quot;https://jozefhajnala.gitlab.io/r/post/data/&quot;
flights &lt;- readRDS(url(paste0(dataurl, &quot;r006/flights.rds&quot;)))
flightsdt &lt;- as.data.table(flights)

bench &lt;- microbenchmark::microbenchmark(
  times = 100,
  base_order   = {flights[order(flights[, &quot;flight&quot;], -xtfrm(flights[, &quot;carrier&quot;])), ] },
  dt_oder      = {flightsdt[order(flight, -carrier), ] },
  dplyr_nse    = {flights %>% arrange(flight, desc(carrier)) },
  dplyr_scoped = {flights %>% arrange_at(&quot;carrier&quot;, desc) %>% arrange_at(&quot;flight&quot;) }
)</code></pre>
<p></p>
<div></div>
<p>Under our particular circumstances, base R’s method seems to be the lowest of the options with data.table being the fastest.</p>
</div>
<div>
<h1>TL;DR – Just want the code</h1>
<blockquote>
<p>No time for reading? <a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/post/data/r008-sorting-data.r" target="_blank">Click here to get just the code with commentary</a></p>
</blockquote>
</div>
<div>
<h1>References</h1>
<ol>
<li><a rel="nofollow" href="https://jozefhajnala.gitlab.io/r/r002-data-manipulation/" target="_blank">post on subsetting</a> on this blog</li>
<li><a rel="nofollow" href="https://www.rdocumentation.org/packages/base/versions/3.5.1/topics/order?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">documentation for base::order</a></li>
<li><a rel="nofollow" href="https://dplyr.tidyverse.org/reference/arrange.html" target="_blank">dplyr’s arrange</a> function reference</li>
<li><a rel="nofollow" href="https://cran.r-project.org/web/packages/data.table/vignettes/datatable-intro.html" target="_blank">introduction to data.table</a></li>
<li><a rel="nofollow" href="http://ec.europa.eu/eurostat/web/sector-accounts/data/annual-data" target="_blank">original eurostat data source</a></li>
</ol>
<h2>Did you find the article helpful or interesting? Help others find it by sharing</h2>
<div></div>
<p><img src="https://i2.wp.com/jozefhajnala.gitlab.io/r/img/r008-01-sort-benchmark.gif?w=456&ssl=1" data-recalc-dims="1"></p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://jozefhajnala.gitlab.io/r/r008-sorting-data/"> Jozef's Rblog</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/7nFf92sCCns" height="1"></a></div>