title: subsetting a nested list based on a conidtion in R
body: <p>my nested list looks like this:</p>
  <pre><code>  myList &lt;- list(structure(list(id = 1:3, value = c(22, 33, 44), 
                                  code = c(&quot;943&quot;, &quot;943&quot;, &quot;3a0&quot;), 
                                  product = c(&quot;Product 1&quot;, &quot;Product 1&quot;, &quot;Product 1&quot;)),
                             row.names = c(NA,-3L), 
                             class = c(&quot;data.table&quot;, &quot;data.frame&quot;)), 
                   structure(list(id = 1:3, value = c(22, 33, 44), 
                                  code = c(&quot;943&quot;, &quot;94f&quot;, &quot;3a0&quot;), 
                                  product = c(&quot;Product 2&quot;, &quot;Product 2&quot;, &quot;Product 2&quot;)),
                             row.names = c(NA,-3L), 
                             class = c(&quot;data.table&quot;, &quot;data.frame&quot;)),
                   structure(list(id = 1:3, value = c(22, 33, 44), 
                                  code = c(&quot;977&quot;, &quot;943&quot;, &quot;3a0&quot;), 
                                  product = c(&quot;Product 3&quot;, &quot;Product 3&quot;, &quot;Product 3&quot;)),
                             row.names = c(NA,-3L), 
                             class = c(&quot;data.table&quot;, &quot;data.frame&quot;)))
  </code></pre>
  <p>i want to remove all list objects that have more than one list element with the same <code>code</code>. For example the first object <code>[[1]]</code> has two entries that have the code <code>943</code>. I want to remove the entire object and keep only those that do not have any duplicates.</p>
  <pre><code>The expected outcome would therefore be:   myList &lt;- list(
      structure(list(id = 1:3, value = c(22, 33, 44), 
                     code = c(&quot;943&quot;, &quot;94f&quot;, &quot;3a0&quot;), 
                     product = c(&quot;Product 2&quot;, &quot;Product 2&quot;, &quot;Product 2&quot;)),
                row.names = c(NA,-3L), 
                class = c(&quot;data.table&quot;, &quot;data.frame&quot;)),
      structure(list(id = 1:3, value = c(22, 33, 44), 
                     code = c(&quot;977&quot;, &quot;943&quot;, &quot;3a0&quot;), 
                     product = c(&quot;Product 3&quot;, &quot;Product 3&quot;, &quot;Product 3&quot;)),
                row.names = c(NA,-3L), 
                class = c(&quot;data.table&quot;, &quot;data.frame&quot;)))
  </code></pre>
  <p>I was thinking of using and lapply, but i couldnt get it to qwork</p>
  <pre><code>any(duplicated(myList[[1]]$code))
  </code></pre>
  <p>any ides or suggestion?</p>
  <p>this seems like a relatively simple problem, but i cant figure it out</p>