title: Nested/grouped tibbles: using purrr:map inside mutate when a function has several arguments
body: <p>I would like to apply a function to each group of a nested/grouped dataset using mutate. This example should help explain the goal. Need advise on how to code this correctly.</p>
  <p>Make a fake dataset that is grouped/nested.</p>
  <pre><code>data(kidney)
  grp_kidney &lt;- kidney %&gt;% group_by(sex) %&gt;% nest()
  </code></pre>
  <p>Which has the following structure:</p>
  <pre><code>&gt; grp_kidney
  # A tibble: 2 x 2
  # Groups:   sex [2]
      sex data             
    &lt;dbl&gt; &lt;list&gt;           
  1     1 &lt;tibble [20 × 6]&gt;
  2     2 &lt;tibble [56 × 6]&gt;
  </code></pre>
  <p>Next we make a function to fit survival curves to this data.</p>
  <pre><code>sFit &lt;- function(df, ci = 'none'){
    survfit(Surv(time, status) ~ age, data = df, conf.type = ci)
  }
  </code></pre>
  <p>Lastly, we apply this function to each row of the grouped data and save the result as a new column in the grouped tibble using purrr::map and dplyr::mutate.</p>
  <pre><code>grp_kidney &lt;- grp_kidney %&gt;%
    mutate(plain = map(grp_kidney$data, sFit, ci = 'plain')) %&gt;%
    mutate(loglog = map(grp_kidney$data, sFit, ci = 'log-log'))
  
  Error: Problem with `mutate()` input `plain`.
  x Input `plain` can't be recycled to size 1.
  ℹ Input `plain` is `map(grp_kidney$data, sFit, ci = &quot;plain&quot;)`.
  ℹ Input `plain` must be size 1, not 2.
  ℹ The error occurred in group 1: sex = 1.
  Run `rlang::last_error()` to see where the error occurred.
  </code></pre>
  <p>What I was hoping to have result in this example is a nested data.frame with the following characteristics:</p>
  <ol>
  <li>One row for each grouping variable element (2 rows in this example)</li>
  <li>Col 1: sex - 1 or 2 in this example</li>
  <li>Col 2: data - the data.frame for each group</li>
  <li>Col 3: plain - output of survfit model with plain CIs</li>
  <li>Col 4: loglog - output of survfit model with log-log CIs</li>
  </ol>
  <p>I can make this work if I make two functions, one for 'plain' and one for 'log-log'. That seems like a waste and would prefer to pass arguments to a more broad function instead. Appreciate help from any coding experts.</p>
  <p>Brant</p>