title: Extract second subelement of every element in a list while ignoring NA's in sapply in R
body: <p>I'm trying to extract the second subelement of every element in a list while ignoring NAs in R.  Here's a small example:</p>
  
  <pre><code>mylist &lt;- list(a=c(6,7),b=NA,c=c(8,9))
  sapply(mylist, "[[", 1)
  sapply(mylist, "[[", 2) #receive error
  </code></pre>
  
  <p>Because element 'b' has only one subelement (NA), I receive the following error when trying to extract the second subelement:</p>
  
  <pre><code>Error in FUN(X[[2L]], ...) : subscript out of bounds
  </code></pre>
  
  <p>My goal is for the output to be: 7, NA, 9.  In other words, I want to <strong>ignore and retain the NAs so that the output is the same length as the number of elements in the list</strong>.  I would like the solution to be general enough to also be able to apply it to a different subelement, n, from each list.</p>