title: Modify elements of a nested list in base R without loops
body: <p>I have a nested list with two or more elements at the top level and want to modify named elements of the sub-lists, e.g. by appending values from a named vector.</p>
  <p>Let's assume <code>L</code> is a list of two elements and <code>N</code>is a vector with the same number of elements:</p>
  <pre class="lang-r prettyprint-override"><code>L &lt;- list(
    foo = list(
      x1=1,
      x2=c(a=1, b=2)
    ),
    bar = list(
      x1=2,
      x2=c(e=2, f=3)
    )
  )
  
  N &lt;- c(n=11, n=12)
  
  </code></pre>
  <p>Then I want to get a result like this:</p>
  <pre class="lang-r prettyprint-override"><code>list(
    foo = list(
      x1=1,
      x2=c(a=1, b=2, n=11)
    ),
    bar = list(
      x1=2,
      x2=c(e=2, f=3, n=12)
    )
  )
  </code></pre>
  <p>It is easy to read the elements of the sub-lists:</p>
  <pre class="lang-r prettyprint-override"><code>lapply(L, &quot;[[&quot;, &quot;x2&quot;)
  </code></pre>
  <p>So I wonder if there is a similarly compact way to change elements.</p>