<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/tidyr-0-5-0/"></div></div><div><a data-url="http://www.r-bloggers.com/tidyr-0-5-0/" data-counturl="http://www.r-bloggers.com/tidyr-0-5-0/" data-count="horizontal" data-text="tidyr 0.5.0" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.rstudio.org/2016/06/13/tidyr-0-5-0/"> RStudio Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I’m pleased to announce tidyr 0.5.0. tidyr makes it easy to “tidy” your data, storing it in a consistent form so that it’s easy to manipulate, visualise and model. Tidy data has a simple convention: put variables in the columns and observations in the rows. You can learn more about it in the <a target="_blank" href="http://cran.r-project.org/web/packages/tidyr/vignettes/tidy-data.html">tidy data</a> vignette. Install it with:</p>
<pre><code>install.packages(&quot;tidyr&quot;)</code></pre>
<p>This release has three useful new features:</p>
<ol>
<li><code>separate_rows()</code> separates values that contain multiple values separated by a delimited into multiple rows. Thanks to <a target="_blank" href="https://github.com/aaronwolen">Aaron Wolen</a> for the contribution!
<pre><code>df &lt;- data_frame(x = 1:2, y = c(&quot;a,b&quot;, &quot;d,e,f&quot;))
df %>% 
  separate_rows(y, sep = &quot;,&quot;)
#> Source: local data frame [5 x 2]
#> 
#>       x     y
#>   &lt;int> &lt;chr>
#> 1     1     a
#> 2     1     b
#> 3     2     d
#> 4     2     e
#> 5     2     f</code></pre>
<p>Compare with <code>separate()</code> which separates into (named) columns:</p>
<pre><code>df %>% 
  separate(y, c(&quot;y1&quot;, &quot;y2&quot;, &quot;y3&quot;), sep = &quot;,&quot;, fill = &quot;right&quot;)
#> Source: local data frame [2 x 4]
#> 
#>       x    y1    y2    y3
#> * &lt;int> &lt;chr> &lt;chr> &lt;chr>
#> 1     1     a     b  &lt;NA>
#> 2     2     d     e     f</code></pre>
</li>
<li><code>spread()</code> gains a <code>sep</code> argument. Setting this will name columns as “key|sep|value”. This is useful when you’re spreading based on a numeric column:
<pre><code>df &lt;- data_frame(
  x = c(1, 2, 1), 
  key = c(1, 1, 2), 
  val = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;)
)
df %>% spread(key, val)
#> Source: local data frame [2 x 3]
#> 
#>       x     1     2
#> * &lt;dbl> &lt;chr> &lt;chr>
#> 1     1     a     c
#> 2     2     b  &lt;NA>
df %>% spread(key, val, sep = &quot;_&quot;)
#> Source: local data frame [2 x 3]
#> 
#>       x key_1 key_2
#> * &lt;dbl> &lt;chr> &lt;chr>
#> 1     1     a     c
#> 2     2     b  &lt;NA></code></pre>
</li>
<li><code>unnest()</code> gains a <code>.sep</code> argument. This is useful if you have multiple columns of data frames that have the same variable names:
<pre><code>df &lt;- data_frame(
  x = 1:2,
  y1 = list(
    data_frame(y = 1),
    data_frame(y = 2)
  ),
  y2 = list(
    data_frame(y = &quot;a&quot;),
    data_frame(y = &quot;b&quot;)
  )
)
df %>% unnest()
#> Source: local data frame [2 x 3]
#> 
#>       x     y     y
#>   &lt;int> &lt;dbl> &lt;chr>
#> 1     1     1     a
#> 2     2     2     b
df %>% unnest(.sep = &quot;_&quot;)
#> Source: local data frame [2 x 3]
#> 
#>       x  y1_y  y2_y
#>   &lt;int> &lt;dbl> &lt;chr>
#> 1     1     1     a
#> 2     2     2     b</code></pre>
<p>It also gains a <code>.id</code> column that makes the names of the list explicit:</p>
<pre><code>df &lt;- data_frame(
  x = 1:2,
  y = list(
    a = 1:3,
    b = 3:1
  )
)
df %>% unnest()
#> Source: local data frame [6 x 2]
#> 
#>       x     y
#>   &lt;int> &lt;int>
#> 1     1     1
#> 2     1     2
#> 3     1     3
#> 4     2     3
#> 5     2     2
#> 6     2     1
df %>% unnest(.id = &quot;id&quot;)
#> Source: local data frame [6 x 3]
#> 
#>       x     y    id
#>   &lt;int> &lt;int> &lt;chr>
#> 1     1     1     a
#> 2     1     2     a
#> 3     1     3     a
#> 4     2     3     b
#> 5     2     2     b
#> 6     2     1     b</code></pre>
</li>
</ol>
<p>tidyr 0.5.0 also includes a bumper crop of bug fixes, including fixes for <code>spread()</code> and <code>gather()</code> in the presence of list-columns. Please see the <a target="_blank" href="https://github.com/hadley/tidyr/releases/tag/v0.5.0">release notes</a> for a complete list of changes.</p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rstudioblog.wordpress.com/2848/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/rstudioblog.wordpress.com/2848/" border="0"></a> <img height="1" alt="" width="1" src="https://pixel.wp.com/b.gif?host=blog.rstudio.org&blog=18843819&%23038;post=2848&%23038;subd=rstudioblog&%23038;ref=&%23038;feed=1" border="0"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/tidyr-0-5-0/"></div></div><div><a data-url="http://www.r-bloggers.com/tidyr-0-5-0/" data-counturl="http://www.r-bloggers.com/tidyr-0-5-0/" data-count="vertical" data-text="tidyr 0.5.0" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://blog.rstudio.org/2016/06/13/tidyr-0-5-0/"> RStudio Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/efO0qXJSfs0"></a></div>