title: How can I make a list-column that is a subset of another list-column in R?
body: <p>I have a data frame with one column as a list-column, i.e. it is a column that has, for each row, two vectors contained in that column. I would like to be able to make another column in my data frame that is also a list-column, but that only contains a single sub-list (rather than two), and I would like that list to be the first three elements of one of the sub-lists of the column with two sub-lists.</p>
  <p>A simple reproducible example is provided below:</p>
  <pre><code>df &lt;- data.frame(state = c(rep(&quot;Alabama&quot;, 5), rep(&quot;Alaska&quot;, 5), rep(&quot;Arizona&quot;, 5), rep(&quot;Arkansas&quot;, 5), rep(&quot;California&quot;, 5)),
             letter = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;h&quot;, &quot;i&quot;, &quot;j&quot;, &quot;k&quot;, &quot;l&quot;, &quot;m&quot;, &quot;n&quot;, &quot;o&quot;, &quot;p&quot;, &quot;q&quot;, &quot;r&quot;, &quot;s&quot;, &quot;t&quot;, &quot;u&quot;, &quot;v&quot;, &quot;w&quot;, &quot;x&quot;, &quot;y&quot;),
             freq = c(8, 7, 4, 3, 1, 19, 15, 7, 4, 2, 10, 6, 3, 2, 2, 11, 10, 10, 5, 4, 50, 33, 22, 11, 1))
  df &lt;- nest(df, letter_list = c(letter, freq))
  </code></pre>
  <p>In the context of this reprex, I would like to have a third column in <code>df</code> that has, for each state, a list of the first three elements of <code>letter</code> (which is contained in <code>letter_list</code>).</p>
  <p>I have attempted to use purrr functions, such as <code>map()</code>, in conjunction with the <code>head()</code> function to <code>mutate</code> a new variable, but this has been unsuccessful; my new column is populated with lists of length 0.</p>
  <p>If possible, a solution using the <code>tidyverse</code> would be ideal.</p>
  <p>Any help would be greatly appreciated!</p>