title: htmlParse missing values NA
body: <p>I'm trying to scrape text from an html document using htmlParse (package: XML) in R. In the code below, I would like to know how return a NA when a tag (e.g., &lt;p class="neg"&gt;) is missing:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="review"&gt;
  &lt;p class="pos"&gt;positive&lt;/p&gt;&lt;p class="neg"&gt;negative&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="review"&gt;
  &lt;p class="pos"&gt;positive&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="review"&gt;
  &lt;p class="pos"&gt;positive&lt;/p&gt;&lt;p class="neg"&gt;negative&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="review"&gt;
  &lt;p class="neg"&gt;negative&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I want the result to look like this:</p>
  
  <p>"positive"    "negative"</p>
  
  <p>"positive"     NA</p>
  
  <p>"positive"    "negative"</p>
  
  <p>NA           "negative"</p>
  
  <p>Thanks!
  Majesus</p>
  
  <p>::::::::::::::::::::::::::::::::::::::::</p>
  
  <p>Chris,
  I have included a new record (hotel_name):</p>
  
  <pre><code>&lt;div class="review"&gt;
  &lt;p class="pos"&gt;positive&lt;/p&gt;&lt;p class="neg"&gt;negative&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="review"&gt;
  &lt;p class="pos"&gt;positive&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="review"&gt;
  &lt;p class="pos"&gt;positive&lt;/p&gt;&lt;p class="neg"&gt;negative&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="review"&gt;
  &lt;p class="neg"&gt;negative&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;div class="hotel"&gt;
  &lt;h3 class="hotel_name"&gt;Hotel Bla&lt;/h3&gt;
  &lt;/div&gt;
  
  
  y &lt;-getNodeSet(doc, "//div")
  
  y &lt;- lapply(y, function(x){
         y  &lt;- xpathSApply(x, ".//p[@class]", xmlValue)
   names(y) &lt;- xpathSApply(x, ".//p[@class]", xmlGetAttr, "class") 
         y  
  })
  
  ldply(y, "rbind")
  
  
  t &lt;-getNodeSet(doc, "//div[@class='hotel']")
  
  t &lt;- lapply(t, function(x){
         t  &lt;- xpathSApply(x, ".//h3[@class='hotel_name']", xmlValue)
   names(t) &lt;- xpathSApply(x, ".//h3[@class='hotel_name']", xmlGetAttr, "class") 
         t  
  })
  
  ldply(t, "rbind")
  </code></pre>
  
  <p>How I can combine both records (y and z) in a table ( CSV ​​) in Excel? "pos", "neg" and "t" must be columns in the same table. Importantly, each "pos" and each "neg" could be composed of different line breaks. I combined cbind and write.table. However, the result is deconfigured.</p>