<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/its-tibbletime-v0-0-2-time-aware-tibbles-new-functions-weather-analysis-and-more/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.business-science.io/code-tools/2017/10/08/tibbletime-0-0-2.html"> business-science.io - Articles</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Today we are introducing <code>tibbletime v0.0.2</code>, and <strong>we’ve got a ton of new features in store for you</strong>. We have functions for converting to flexible time periods with the <code>~period formula~</code> and making/calculating custom rolling functions with <code>rollify()</code> (plus a bunch more new functionality!). We’ll take the new functionality for a spin with some weather data (from the <code>weatherData</code> package). However, the new tools make <code>tibbletime</code> useful in a number of broad applications such as <strong>forecasting, financial analysis, business analysis and more</strong>! We truly view <code>tibbletime</code> as the next phase of time series analysis in the <code>tidyverse</code>. If you like what we do, please <a rel="nofollow" href="http://www.business-science.io/code-tools/2017/10/08/tibbletime-0-0-2.html#social" target="_blank">connect with us on social media</a> to stay up on the latest <a rel="nofollow" href="http://www.business-science.io/code-tools/2017/10/08/tibbletime-0-0-2.html#contact" target="_blank">Business Science</a> news, events and information!</p>
<h2>Introduction</h2>
<p><img alt="Tibbletime v0.0.2" src="https://i1.wp.com/www.business-science.io/assets/tibbletime-0-0-2.png?w=456" data-recalc-dims="1"></p>
<p>We are excited to announce the release of <code>tibbletime v0.0.2</code> on CRAN. Loads of new<br>
functionality have been added, including:</p>
<ul>
<li>
<p><strong>Generic period support</strong>: Perform time-based calculations by a number<br>
of supported periods using a new <code>~period formula~</code>.</p>
</li>
<li>
<p><strong>Creating series</strong>: Use <code>create_series()</code> to quickly create a <code>tbl_time</code><br>
object initialized with a regular time series.</p>
</li>
<li>
<p><strong>Rolling calculations</strong>: Turn any function into a rolling version of itself with<br>
<code>rollify()</code>.</p>
</li>
<li>
<p>A number of smaller tweaks and helper functions to make life easier.</p>
</li>
</ul>
<p>As we further develop <code>tibbletime</code>, it is becoming clearer that the package<br>
is a tool that should be used <em>in addition</em> to the rest of the <code>tidyverse</code>.<br>
<strong>The combination of the two makes time series analysis in the tidyverse much easier to do!</strong></p>
<h2>In this post</h2>
<p>Today we will take a look at weather data for New York and San<br>
Francisco from 2013. It will be an exploratory analysis<br>
to show off some of the new features in <code>tibbletime</code>, but the package<br>
itself has much broader application. As we will see, <code>tibbletime</code>’s time-based<br>
functionality can be a valuable data manipulation tool to help with:</p>
<ul>
<li>
<p>Product and sales forecasting</p>
</li>
<li>
<p>Financial analysis with custom rolling functions</p>
</li>
<li>
<p>Grouping data into time buckets to analyze change over time, which is great for any part of an organization including sales, marketing, manufacturing, and HR!</p>
</li>
</ul>
<h3>Data and packages</h3>
<p>The datasets used are from a neat package called <code>weatherData</code>. While <code>weatherData</code> has functionality to pull weather data for a number of cities, we will use the built-in datasets. We encourage you to explore the <code>weatherData</code> API if you’re interested in collecting weather data.</p>
<p>To get started, load the following packages:</p>
<ul>
<li><code>tibbletime</code>: Time-aware tibbles for the tidyverse</li>
<li><code>tidyverse</code>: Loads packages including <code>dplyr</code>, <code>tidyr</code>, <code>purrr</code>, and <code>ggplot</code></li>
<li><code>corrr</code>: Tidy correlations</li>
<li><code>weatherData</code>: Slick package for getting weather data</li>
</ul>
<p>Also, load the datasets from <code>weatherData</code>, “NewYork2013” and “SFO2013”.</p>
<figure>
<pre><code data-lang="r"><span># Load libraries
</span><span>library</span><span>(</span><span>tibbletime</span><span>)</span><span> </span><span># Make sure you have 0.0.2 from CRAN!
</span><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>library</span><span>(</span><span>corrr</span><span>)</span><span>
</span><span>library</span><span>(</span><span>weatherData</span><span>)</span><span>
</span><span># Load weatherData datasets
</span><span>NYC</span><span> </span><span>&lt;-</span><span> </span><span>NewYork2013</span><span>
</span><span>SFO</span><span> </span><span>&lt;-</span><span> </span><span>SFO2013</span></code></pre>
</figure>
<h3>Combine and convert</h3>
<p>To tidy up, we first join our data sets together using <code>bind_rows()</code>. Passing<br>
a named list of tibbles along with specifying the <code>.id</code> argument allows<br>
<code>bind_rows()</code> to create a new <code>City</code> reference column for us.</p>
<figure>
<pre><code data-lang="r"><span># Tidying up the weather data
</span><span>weather</span><span> </span><span>&lt;-</span><span> </span><span>bind_rows</span><span>(</span><span>list</span><span>(</span><span>NYC</span><span> </span><span>=</span><span> </span><span>NYC</span><span>,</span><span> </span><span>SFO</span><span> </span><span>=</span><span> </span><span>SFO</span><span>),</span><span> </span><span>.id</span><span> </span><span>=</span><span> </span><span>&quot;City&quot;</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>as_tibble</span><span>()</span><span>
</span><span>weather</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## # A tibble: 19,706 x 3
##     City                Time Temperature
##    </code></pre></figure>