title: Handling vectors of different lengths in purrr
body: <p>I currently have the following <code>R</code>code that runs multiple regression models with different predictors, across different subsets, and returns tidied output using the <code>broom</code> package. </p>
  
  <pre><code>library(dplyr) 
  library(purrr)
  library(broom)
  cars &lt;- mtcars
  preds&lt;-c("disp", "drat", "wt")
  model_fits &lt;- map_df(preds, function(pred) {
    model_formula &lt;- sprintf("mpg ~ %s", pred)  
    cars %&gt;%
      group_by(cyl) %&gt;%
        do(tidy(lm(model_formula, data = .), conf.int = T)) %&gt;% 
        filter(term == pred) %&gt;%
        mutate(outcome = "mpg") %&gt;%
      select(outcome, cyl:estimate, starts_with("conf."))
  })
  </code></pre>
  
  <p>This results in the following data frame: </p>
  
  <pre><code>&gt; model_fits
  Source: local data frame [9 x 6]
  Groups: cyl [3]
  
    outcome   cyl  term     estimate    conf.low     conf.high
      &lt;chr&gt; &lt;dbl&gt; &lt;chr&gt;        &lt;dbl&gt;       &lt;dbl&gt;         &lt;dbl&gt;
  1     mpg     4  disp -0.135141815 -0.21018121 -0.0601024237
  2     mpg     6  disp  0.003605119 -0.03638572  0.0435959552
  3     mpg     8  disp -0.019634095 -0.03993175  0.0006635639
  4     mpg     4  drat  5.235016267 -3.19097359 13.6610061249
  5     mpg     6  drat  0.350268953 -3.13669610  3.8372340053
  6     mpg     8  drat  0.329543608 -3.98975120  4.6488384177
  7     mpg     4    wt -5.647025261 -9.83228414 -1.4617663781
  8     mpg     6    wt -2.780105939 -6.21162010  0.6514082171
  9     mpg     8    wt -2.192437926 -3.80310208 -0.5817737772
  </code></pre>
  
  <p>What is the best way of incorporating a vector of outcomes (e.g., <code>outcomes&lt;-c("mpg", "qsec")</code>) into this script without using the loop functions? I've considered the <code>map2_df</code> function in the <code>purrr</code> package but it requires both vectors to be of the same length. My desired data frame would look like this: </p>
  
  <pre><code>   outcome   cyl  term     estimate     conf.low     conf.high
       &lt;chr&gt; &lt;dbl&gt; &lt;chr&gt;        &lt;dbl&gt;        &lt;dbl&gt;         &lt;dbl&gt;
  1      mpg     4  disp -0.135141815 -0.210181205 -0.0601024237
  2      mpg     6  disp  0.003605119 -0.036385718  0.0435959552
  3      mpg     8  disp -0.019634095 -0.039931754  0.0006635639
  4      mpg     4  drat  5.235016267 -3.190973592 13.6610061249
  5      mpg     6  drat  0.350268953 -3.136696100  3.8372340053
  6      mpg     8  drat  0.329543608 -3.989751201  4.6488384177
  7      mpg     4    wt -5.647025261 -9.832284144 -1.4617663781
  8      mpg     6    wt -2.780105939 -6.211620095  0.6514082171
  9      mpg     8    wt -2.192437926 -3.803102076 -0.5817737772
  10    qsec     4  disp  0.020522320 -0.024081106  0.0651257460
  11    qsec     6  disp  0.032395786  0.003380046  0.0614115258
  12    qsec     8  disp  0.003443553 -0.007442996  0.0143301028
  13    qsec     4  drat -1.304473000 -4.633470581  2.0245245810
  14    qsec     6  drat -2.234114977 -5.457932913  0.9897029580
  15    qsec     8  drat -2.645047137 -3.791162337 -1.4989319372
  16    qsec     4    wt  1.884663596  0.169516461  3.5998107312
  17    qsec     6    wt  4.147883561  1.394030756  6.9017363651
  18    qsec     8    wt  0.845029716  0.009104550  1.6809548809
  </code></pre>