title: unlist column of lists of single values
body: <p>I have been generating some features for clustering and needed the correlation coefficient based off of customer claims submitted over time. I used this code to get the coefficient by running a <code>lm</code> model over nested tibbles of data: </p>
  
  <pre><code>provProfileTemp &lt;- byProvProfile %&gt;% 
    mutate(date = ymd(paste(Year, Month, "01", sep = "-"))) %&gt;% 
    select(-Month, -Year) %&gt;% 
    group_by(AccountNumber, date) %&gt;% 
    count() %&gt;% 
    group_by(AccountNumber) %&gt;% 
    mutate(total_claims = sum(n)) %&gt;% 
    ungroup() %&gt;% 
    mutate(numeric_date = as.numeric(date)/(24*60*60)) %&gt;% # POSIX conversion for summary(lm)
    select(AccountNumber, numeric_date, claims = n, total_claims) %&gt;% 
    nest(-AccountNumber, -total_claims)
  
  coeffs &lt;- provProfileTemp %&gt;% 
    mutate(
      fit = map(provProfileTemp$data, ~lm(numeric_date ~ claims, data = .)), 
      results = map(fit, summary, correlation = TRUE), 
      coeff = results %&gt;% map(c("correlation")) %&gt;% map(3)
    ) %&gt;% 
   select(AccountNumber, coeff, total_claims) 
  </code></pre>
  
  <p>The top block creates the variables needed for the regression line and nests the data into a tibble with the account number, total claims, and a tibble of the data for the regression. Using <code>purrr::map</code> in the second block, I'm able to fit a line, get the results from the summary, and pull the coeff from the summary. </p>
  
  <p>The results are correct and work fine, however, the new column is a list with the single value of the coefficient in it. I cannot get compress the list to use the new column as just the coefficient and not a list. Using <code>unlist()</code> gives this error: <code>Error in mutate_impl(.data, dots) : Column</code>coeff<code>must be length 27768 (the number of rows) or one, not 21949</code>. This is happening because <code>unlist()</code> is not returning the same number of elements. I have had similar results with functions like <code>purrr::flatten</code> or <code>unlist(lapply(coeff, "[[", 1))</code>. </p>
  
  <p>Any suggestions on how I can flatten the list properly into a single value or approach the problem in a different way which doesn't require generating the coefficient like this? Any help is greatly appreciated. Thank you. </p>
  
  <p>This is what the data looks like: </p>
  
  <pre><code>AccountNumber       coeff  total_claims
          &lt;int&gt;      &lt;list&gt;         &lt;int&gt;
             16   &lt;dbl [1]&gt;           494     
             19   &lt;dbl [1]&gt;           184     
             45   &lt;dbl [1]&gt;            81...
  </code></pre>
  
  <p>Here is dummy data: </p>
  
  <pre><code>provProfileTemp &lt;- structure(list(AccountNumber = c(1L, 1L, 1L, 1L, 
       1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
       2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L
       ), Year = c(2018L, 2017L, 2018L, 2018L, 2018L, 2017L, 2018L, 
       2018L, 2018L, 2018L, 2018L, 2018L, 2018L, 2018L, 2018L, 2018L, 
       2018L, 2018L, 2018L, 2018L), Month = c(4L, 11L, 1L, 1L, 3L, 10L, 
       1L, 3L, 7L, 1L, 5L, 10L, 5L, 2L, 4L, 4L, 4L, 3L, 2L, 1L)), .Names =               c("AccountNumber", 
       "Year", "Month"), row.names = c(NA, -20L), class = c("tbl_df", 
       "tbl", "data.frame"))
  </code></pre>