title: multiple maps to mutate a data frame and add a column
body: <p>I am working with some data which looks like:</p>
  
  <pre><code># A tibble: 2 x 3
    splits          id        inner_resamples 
    &lt;named list&gt;    &lt;chr&gt;     &lt;named list&gt;    
  1 &lt;split [20/20]&gt; Resample1 &lt;tibble [6 x 2]&gt;
  2 &lt;split [20/20]&gt; Resample2 &lt;tibble [6 x 2]&gt;
  </code></pre>
  
  <p>What I want to do is to <code>map</code> over the <code>inner_resamples</code> column and <code>map</code> again over the <code>splits</code> column in each <code>inner_resamples</code> column. For each list I would like to <code>map</code> again.</p>
  
  <p>The way to do this is to use the <code>analysis</code> function from the <code>rsample</code> package.</p>
  
  <pre><code>map(cv_rolling$inner_resamples$`1`$splits, ~ analysis(.x)) %&gt;% tail()
  </code></pre>
  
  <p>What I would like to do is to map over each of the outputs and create new data 7 columns:</p>
  
  <pre><code>    &gt; map(cv_rolling$inner_resamples$`1`$splits, ~ analysis(.x)) %&gt;% tail()
  [[1]]
  # A tibble: 2 x 4
    time       ID    Value   out
    &lt;date&gt;     &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;
  1 2016-12-13 CAT1   796.     1
  2 2016-12-14 CAT1   797.     0
  
  [[2]]
  # A tibble: 2 x 4
    time       ID    Value   out
    &lt;date&gt;     &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;
  1 2016-12-15 CAT1   798.     1
  2 2016-12-16 CAT1   791.     0
  
  [[3]]
  # A tibble: 2 x 4
    time       ID    Value   out
    &lt;date&gt;     &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;
  1 2016-12-19 CAT1   794.     1
  2 2016-12-20 CAT1   796.     0
  
  [[4]]
  # A tibble: 2 x 4
    time       ID    Value   out
    &lt;date&gt;     &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;
  1 2016-12-21 CAT1   795.     0
  2 2016-12-22 CAT1   791.     0
  
  [[5]]
  # A tibble: 2 x 4
    time       ID    Value   out
    &lt;date&gt;     &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;
  1 2016-12-23 CAT1   790.     0
  2 2016-12-27 CAT1   792.     1
  
  [[6]]
  # A tibble: 2 x 4
    time       ID    Value   out
    &lt;date&gt;     &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;
  1 2016-12-28 CAT1   785.     0
  2 2016-12-29 CAT1   783.     0
  </code></pre>
  
  <p>Expected output would be (for 1 of the outputs)</p>
  
  <pre><code>[[6]]
  # A tibble: 2 x 4
    time       ID    Value   out    NEWCOL
    &lt;date&gt;     &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;    
  1 2016-12-28 CAT1   785.     0    8677 
  2 2016-12-29 CAT1   783.     0    8757
  </code></pre>
  
  <p>However I would like to also do this for each <code>N</code> in the data:</p>
  
  <pre><code>map(cv_rolling$inner_resamples$`N`$splits, ~ analysis(.x)) %&gt;% tail()
  </code></pre>
  
  <p>Where <code>N</code> here can be accessed by:</p>
  
  <pre><code>cv_rolling$inner_resamples[[1]]
  cv_rolling$inner_resamples[[2]]
  cv_rolling$inner_resamples[[N]]
  </code></pre>
  
  <p>New Data:</p>
  
  <pre><code>structure(list(time = structure(c(17136, 17137, 17140, 17141, 
  17142, 17143, 17144, 17147, 17148, 17149, 17150, 17151, 17154, 
  17155, 17156, 17157, 17158, 17162, 17163, 17164, 17165, 17136, 
  17137, 17140, 17141, 17142, 17143, 17144, 17147, 17148, 17149, 
  17150, 17151, 17154, 17155, 17156, 17157, 17158, 17162, 17163, 
  17164, 17165), class = "Date"), ID = c("CAT1", "CAT1", "CAT1", 
  "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", 
  "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", 
  "CAT1", "CAT1", "CAT2", "CAT2", "CAT2", "CAT2", "CAT2", "CAT2", 
  "CAT2", "CAT2", "CAT2", "CAT2", "CAT2", "CAT2", "CAT2", "CAT2", 
  "CAT2", "CAT2", "CAT2", "CAT2", "CAT2", "CAT2", "CAT2"), Value = c(747.919983, 
  750.5, 762.52002, 759.109985, 771.190002, 776.419983, 789.289978, 
  789.27002, 796.099976, 797.070007, 797.849976, 790.799988, 794.200012, 
  796.419983, 794.559998, 791.26001, 789.909973, 791.549988, 785.049988, 
  782.789978, 771.820007, 56.283112, 56.330643, 57.252861, 56.996159, 
  58.346195, 58.003925, 58.916634, 59.106773, 59.876858, 59.591648, 
  59.496574, 59.230362, 60.485325, 60.409275, 60.409275, 60.418777, 
  60.124058, 60.162071, 59.886375, 59.800812, 59.078251), out = c(0, 
  1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 
  1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0)), row.names = c(NA, 
  -42L), index_quo = ~date, index_time_zone = "UTC", class = c("tbl_time", 
  "tbl_df", "tbl", "data.frame"))
  </code></pre>
  
  <p>Also need to run:</p>
  
  <pre><code>library(rsample)
  library(purrr)
  library(tibbletime)
  
  periods_train &lt;- 2
  periods_test  &lt;- 1
  skip_span     &lt;- 1
  
  cv_rolling &lt;- nested_cv(df, 
                          outside = group_vfold_cv(group = "ID"),
                          inside = rolling_origin(
                            initial    = periods_train,
                            assess     = periods_test,
                            cumulative = FALSE,
                            skip       = skip_span))
  </code></pre>
  
  <p>Where the following can be run: </p>
  
  <pre><code>map(cv_rolling$inner_resamples$`2`$splits, ~ analysis(.x))
  </code></pre>
  
  <p>Which is what I am trying to modify / create new data from.</p>