title: Spread with duplicate identifiers (using tidyverse and %>%)
body: <h1>My data looks like this:</h1>
  
  <p><a href="https://i.stack.imgur.com/kZR90.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kZR90.png" alt="enter image description here"></a></p>
  
  <h1>I am trying to make it look like this:</h1>
  
  <p><a href="https://i.stack.imgur.com/9xLyz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9xLyz.png" alt="enter image description here"></a></p>
  
  <p>I would like to do this in tidyverse using %>%-chaining.</p>
  
  <pre><code>df &lt;- 
  structure(list(id = c(2L, 2L, 4L, 5L, 5L, 5L, 5L), start_end = structure(c(2L, 
  1L, 2L, 2L, 1L, 2L, 1L), .Label = c("end", "start"), class = "factor"), 
      date = structure(c(6L, 7L, 3L, 8L, 9L, 10L, 11L), .Label = c("1979-01-03", 
      "1979-06-21", "1979-07-18", "1989-09-12", "1991-01-04", "1994-05-01", 
      "1996-11-04", "2005-02-01", "2009-09-17", "2010-10-01", "2012-10-06"
      ), class = "factor")), .Names = c("id", "start_end", "date"
  ), row.names = c(3L, 4L, 7L, 8L, 9L, 10L, 11L), class = "data.frame")
  </code></pre>
  
  <h1>What I have tried:</h1>
  
  <pre><code>data.table::dcast( df, formula = id ~ start_end, value.var = "date", drop = FALSE )  # does not work because it summarises the data
  
  tidyr::spread( df, start_end, date )  # does not work because of duplicate values
  
  
  df$id2 &lt;- 1:nrow(df)
  tidyr::spread( df, start_end, date ) # does not work because the dataset now has too many rows.
  </code></pre>
  
  <p>These questions do not answer my question:</p>
  
  <p><a href="https://stackoverflow.com/questions/39053451/using-spread-with-duplicate-identifiers-for-rows">Using spread with duplicate identifiers for rows</a>  (because they summarise)</p>
  
  <p><a href="https://stackoverflow.com/questions/31209388/r-spread-function-on-data-frame-with-duplicates">R: spread function on data frame with duplicates</a>  (because they paste the values together)</p>
  
  <p><a href="https://stackoverflow.com/questions/35932291/reshaping-data-in-r-with-login-logout-times">Reshaping data in R with &quot;login&quot; &quot;logout&quot; times</a> (because not specifically asking for/answered using tidyverse and chaining)</p>