title: R - dplyr map slice for repeat rows
body: <p>I have trouble combining <code>slice</code> and <code>map</code>. </p>
  
  <p>I am interested of doing something similar to <a href="https://stackoverflow.com/questions/38237350/repeating-rows-of-data-frame-in-dplyr">this</a>; which is, in my case, transforming a compact person-period file to a long (sequential) person-period one. However, because my file is too big, I need to split the data first. </p>
  
  <p>My data look like this</p>
  
  <pre><code>    group id var ep dur
  1      A  1   a  1  20
  2      A  1   b  2  10
  3      A  1   a  3   5
  4      A  2   b  1   5
  5      A  2   b  2  10
  6      A  2   b  3  15
  7      B  1   a  1  20
  8      B  1   a  2  10
  9      B  1   a  3  10
  10     B  2   c  1  20
  11     B  2   c  2   5
  12     B  2   c  3  10
  </code></pre>
  
  <p>What I need is simply this (answer from <a href="https://stackoverflow.com/questions/38237350/repeating-rows-of-data-frame-in-dplyr">this</a>)</p>
  
  <pre><code>library(dplyr)
  dt %&gt;% slice(rep(1:n(),.$dur))
  </code></pre>
  
  <p>However, I am interested in introducing a <code>split(.$group)</code>. </p>
  
  <p>How I am suppose to do so ?</p>
  
  <pre><code>dt %&gt;% split(.$group) %&gt;% map_df(slice(rep(1:n(),.$dur)))
  </code></pre>
  
  <p>Is not working for example. </p>
  
  <p>My desired output is the same as <code>dt %&gt;% slice(rep(1:n(),.$dur))</code>
  which is </p>
  
  <pre><code>     group id var ep dur
  1       A  1   a  1  20
  2       A  1   a  1  20
  3       A  1   a  1  20
  4       A  1   a  1  20
  5       A  1   a  1  20
  6       A  1   a  1  20
  7       A  1   a  1  20
  8       A  1   a  1  20
  9       A  1   a  1  20
  10      A  1   a  1  20
  .....
  </code></pre>
  
  <p>But I need to <code>split</code> this operation because the file is too big. </p>
  
  <p>data </p>
  
  <pre><code>dt = structure(list(group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 
  2L, 2L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor"), 
  id = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 
  2L, 2L), .Label = c("1", "2"), class = "factor"), var = structure(c(1L, 
  2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 3L, 3L, 3L), .Label = c("a", 
  "b", "c"), class = "factor"), ep = structure(c(1L, 2L, 3L, 
  1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("1", "2", 
  "3"), class = "factor"), dur = c(20, 10, 5, 5, 10, 15, 20, 
  10, 10, 20, 5, 10)), .Names = c("group", "id", "var", "ep", 
  "dur"), row.names = c(NA, -12L), class = "data.frame")
  </code></pre>