<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/a-tour-of-the-tibble-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://tjmahr.github.io/tibble-package-tour/"> Higher Order Functions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Dataframes are used in R to hold tabular data. Think of the prototypical<br>
spreadsheet or database table: a grid of data arranged into rows and columns.<br>
That’s a dataframe. The <a rel="nofollow" href="http://tibble.tidyverse.org/" target="_blank">tibble R package</a><br>
provides a fresh take on dataframes to fix some longstanding annoyances with<br>
them. For example, printing a large tibble shows just the first 10 rows instead<br>
of the flooding the console with the first 1,000 rows.</p>
<p>In this post, I provide a tour of the tibble package. Because the package<br>
provides tools for working with tabular data, it also contain some less<br>
well-known helper functions that I would like to advertise in this post. In<br>
particular, I find <code>add_column()</code>, <code>rownames_to_column()</code> and<br>
<code>rowid_to_column()</code> to be useful tools in my work.</p>
<p><strong>Why the name “tibble”?</strong> Tibbles first appeared in the dplyr package in<br>
January 2014, but they weren’t called “tibbles” yet. dplyr used a subclass<br>
<code>tbl_df</code> for its dataframe objects and they behaved like modern tibbles: Better<br>
printing, not converting strings to factors, etc. We loved them, and we would<br>
convert our plain-old dataframes into these <code>tbl_df</code>s for these features.<br>
However, the name tee-bee-ell-dee-eff is quite a mouthful. On Twitter,<br>
<a rel="nofollow" href="https://twitter.com/JennyBryan/status/514652585488576512" target="_blank">@JennyBryan raised the question of how to pronounce<br>
<code>tbl_df</code></a>, and<br>
<a rel="nofollow" href="https://twitter.com/kevin_ushey/status/514659005621219329" target="_blank">@kevin_ushey suggested “tibble<br>
diff”</a>. The name was<br>
enthusiastically received.</p>
<h2>Creating tibbles</h2>
<p>Create a fresh tibble using <code>tibble()</code> and vectors of values for each column.<br>
The column definitions are evaluated sequentially, so additional columns can be<br>
created by manipulating earlier defined ones. Below <code>x</code> is defined and then the<br>
values of <code>x</code> are manipulated to create the column <code>x_squared</code>.</p>
<div>
<pre><code><span>library</span><span>(</span><span>tibble</span><span>)</span><span>
</span><span>library</span><span>(</span><span>magrittr</span><span>)</span><span>
</span><span>tibble</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>1</span><span>:</span><span>5</span><span>,</span><span> </span><span>x_squared</span><span> </span><span>=</span><span> </span><span>x</span><span> </span><span>^</span><span> </span><span>2</span><span>)</span><span>
</span><span>#> # A tibble: 5 x 2
#> x x_squared
#> </span></code></pre></div>