title: Pivoting in r with dplyr
body: <p>Here's a data frame:</p>
  
  <pre><code>sample_data &lt;- data.frame(
    Device = c("Desktop", "Desktop", "Desktop", "Tablet", "Tablet", "Tablet", "Mobile", "Mobile", "Mobile"),
    Date_Range = seq(as.Date("2017-01-01"), as.Date("2017-01-30"), by = 1),
    Sessions = ceiling(rnorm(90, mean = 3000, sd = 300)),
    Conversion1 = ceiling(rnorm(90, mean = 800, sd = 100)),
    Conversion2 = ceiling(rnorm(90, mean = 400, sd = 50))
  )
  </code></pre>
  
  <p>And it looks like this:</p>
  
  <pre><code>head(sample_data)
     Device Date_Range Sessions Conversion1 Conversion2
  1 Desktop 2017-01-01     2906         920         361
  2 Desktop 2017-01-02     2604         873         380
  3 Desktop 2017-01-03     2449         781         398
  4  Tablet 2017-01-04     3205         851         534
  5  Tablet 2017-01-05     3099         622         341
  6  Tablet 2017-01-06     2708         842         386
  </code></pre>
  
  <p>If there was only one metric (there's actually 3: Sessions + 2 conversion columns) and I wanted columns as dates for a trended table I could go:</p>
  
  <pre><code>sample_data_spread &lt;- tbl_df(sample_data) %&gt;%
    group_by(Date_Range) %&gt;%
    summarize(Sessions = sum(Sessions)) %&gt;%
    spread(key = Date_Range, value = Sessions)
  </code></pre>
  
  <p>This looks like:</p>
  
  <pre><code>&gt; sample_data_spread[,1:5]
  # A tibble: 1 × 5
    `2017-01-01` `2017-01-02` `2017-01-03` `2017-01-04` `2017-01-05`
           &lt;dbl&gt;        &lt;dbl&gt;        &lt;dbl&gt;        &lt;dbl&gt;        &lt;dbl&gt;
  1         9238         8937         9129         9384         8222
  </code></pre>
  
  <p>But what I actually want is a table with the following format:</p>
  
  <ul>
  <li>columns: the dates like I have now</li>
  <li>rows: sessions, Conversion1, Conversion2</li>
  <li>I'm ignoring Device column for now</li>
  </ul>
  
  <p>What is a good way to do this?</p>