title: how do I get the difference between two R named lists?
body: <p>OK, I've got two named lists, one is "expected" and one is "observed". They may be complex in structure, with arbitrary data types. I want to get a new list containing just those elements of the observed list that are different from what's in the expected list. Here's an example:</p>
  
  <pre><code>Lexp &lt;- list(a=1, b="two", c=list(3, "four"))
  Lobs &lt;- list(a=1, c=list(3, "four"), b="ni")
  Lwant &lt;- list(b="ni")
  </code></pre>
  
  <p>Lwant is what I want the result to be. I tried this:</p>
  
  <pre><code>&gt; setdiff(Lobs, Lexp)
  [[1]]
  [1] "ni"
  </code></pre>
  
  <p>Nope, that loses the name, and I don't think setdiff pays attention to the names. Order clearly doesn't matter here, and I don't want <em>a=1</em> to match with <em>b=1</em>. </p>
  
  <p>Not sure what a good approach is... Something that loops over a list of <em>names(Lobs)</em>? Sounds clumsy and non-R-like, although workable... Got any elegant ideas?</p>